Upgrade LBCAlerte to version 3.3

Add upgrade script
This commit is contained in:
Jimmy Monin
2016-11-26 19:19:16 +01:00
parent a7c054b535
commit 58ffd500e6
89 changed files with 6436 additions and 758 deletions

View File

@ -0,0 +1,57 @@
<?php
namespace App\Storage;
use App\Ad\Ad as AdItem;
class AdPhoto
{
protected $_user;
public function __construct(\App\User\User $user)
{
$this->_user = $user;
}
public function getPublicDestination($filename = null)
{
$destination = "static/media/annonce/".$this->_user->getUsername();
if ($filename) {
$destination .= "/".$filename;
}
return $destination;
}
public function getDestination()
{
return DOCUMENT_ROOT."/static/media/annonce/".$this->_user->getUsername();
}
public function import(AdItem $ad, $override = false)
{
$destination = $this->getDestination();
if (!is_dir($destination) && !mkdir($destination)) {
return false;
}
foreach ($ad->getPhotos() AS $photo) {
$filename = $destination."/".$photo["local"];
if (!is_file($filename) || $override) {
copy($photo["remote"], $filename);
}
}
return true;
}
public function delete(AdItem $ad)
{
$destination = $this->getDestination();
foreach ($ad->getPhotos() AS $photo) {
$filename = $destination."/".$photo["local"];
if (is_file($filename)) {
unlink($filename);
}
}
}
}