* album export
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
|
||||
use App\Entity\Image;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Imagine\Gd\Imagine;
|
||||
@@ -17,6 +16,7 @@ class GalleryService
|
||||
|
||||
const CONFIG_FILE = 'data/galleries/config.yaml';
|
||||
const IMAGE_BASEDIR = 'data/galleries/%s/';
|
||||
const EXPORT_DIR = 'data/export/';
|
||||
const THUMBNAIL_SIZE = 500;
|
||||
|
||||
protected $contentTypeMap = [
|
||||
@@ -36,25 +36,38 @@ class GalleryService
|
||||
$this->em = $entityManager;
|
||||
}
|
||||
|
||||
public function exportGallery(string $slug)
|
||||
public function getExportFileName(string $slug)
|
||||
{
|
||||
$config = $this->getConfig();
|
||||
|
||||
if (!isset($config['galleries'][$slug])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$dir = $config['galleries'][$slug]['dir'];
|
||||
$images = array_map('basename', glob(sprintf(self::IMAGE_BASEDIR . "*.{jpg,jpeg,png}", $dir), GLOB_BRACE));
|
||||
return $this->ensureExportFileExists($dir, "{$slug}.zip");
|
||||
}
|
||||
|
||||
private function ensureExportFileExists(string $dir, string $filename)
|
||||
{
|
||||
$exportName = self::EXPORT_DIR . $filename;
|
||||
if(file_exists($exportName)) {
|
||||
return $exportName;
|
||||
}
|
||||
|
||||
$images = array_map('basename', glob($this->getImageDir($dir) . "*.{jpg,jpeg,png}", GLOB_BRACE));
|
||||
|
||||
$zipName = tempnam("data/tmp", "export");
|
||||
$zipArchive = new \ZipArchive();
|
||||
$zipArchive->open($zipName, \ZipArchive::CREATE);
|
||||
foreach ($images as $image) {
|
||||
$zipArchive->addFile("{$dir}/{$image}");
|
||||
ini_set("max_execution_time", 60);
|
||||
$zipArchive->addFile(
|
||||
sprintf(self::IMAGE_BASEDIR,$dir) . $image,
|
||||
"{$dir}/{$image}"
|
||||
);
|
||||
}
|
||||
$zipArchive->close();
|
||||
return $zipName;
|
||||
rename($zipName, $exportName);
|
||||
return $exportName;
|
||||
}
|
||||
|
||||
public function loadGalleryData($includeHidden = false)
|
||||
|
||||
Reference in New Issue
Block a user