public function __construct() { $this->acl = Bootstrap::get('acl'); $this->adapter = Bootstrap::get('ZendDb'); // Fetch files settings $Settings = new DirectusSettingsTableGateway($this->acl, $this->adapter); $this->filesSettings = $Settings->fetchCollection('files', array('storage_adapter', 'storage_destination', 'thumbnail_storage_adapter', 'thumbnail_storage_destination', 'thumbnail_size', 'thumbnail_quality', 'thumbnail_crop_enabled')); // Initialize Storage Adapters $StorageAdapters = new DirectusStorageAdaptersTableGateway($this->acl, $this->adapter); $adapterRoles = array('DEFAULT', 'THUMBNAIL', 'TEMP'); $storage = $StorageAdapters->fetchByUniqueRoles($adapterRoles); if (count($storage) !== count($adapterRoles)) { throw new \RuntimeException(__CLASS__ . ' expects adapter settings for these default adapter roles: ' . implode(',', $adapterRoles)); } $this->FilesStorage = self::getStorage($storage['DEFAULT']); $this->ThumbnailStorage = self::getStorage($storage['THUMBNAIL']); $this->storageAdaptersByRole = $storage; }
$supportedExtensions = array('jpg', 'jpeg', 'png', 'gif'); out("Running script with the following supported extensions: " . implode(", ", $supportedExtensions)); $db = \Directus\Bootstrap::get('ZendDb'); $acl = \Directus\Bootstrap::get('acl'); $Settings = new DirectusSettingsTableGateway($acl, $db); $filesSettings = $Settings->fetchCollection('media', array('storage_adapter', 'storage_destination', 'thumbnail_storage_adapter', 'thumbnail_storage_destination', 'thumbnail_size', 'thumbnail_quality', 'thumbnail_crop_enabled')); $StorageAdapters = new DirectusStorageAdaptersTableGateway($acl, $db); $storageAdaptersById = $StorageAdapters->fetchAllWithIdKeys(); foreach ($storageAdaptersById as $id => $storageAdapter) { $storageAdaptersById[$id] = \Directus\Files\Storage\Storage::getStorage($storageAdapter); } out("\nLoaded " . count($storageAdaptersById) . " storage adapters."); $DirectusMedia = new TableGateway('directus_files', $db); $mediaRecords = $DirectusMedia->select(); out("Found " . $mediaRecords->count() . " Directus media records."); $thumbnailStorageAdapterResultSet = $StorageAdapters->fetchByUniqueRoles(array('THUMBNAIL')); if (1 != count($thumbnailStorageAdapterResultSet)) { throw new \RuntimeException("Fatal: exactly one storage adapter with role THUMBNAIL is required"); } $thumbnailStorageAdapterSettings = array_pop($thumbnailStorageAdapterResultSet); if ('FileSystemAdapter' != $thumbnailStorageAdapterSettings['adapter_name']) { throw new \RuntimeException("Fatal: THUMBNAIL storage adapter: only FileSystemAdapter is currently supported by this script"); } $thumbnailStorageAdapter = $storageAdaptersById[$thumbnailStorageAdapterSettings['id']]; $tempStorageAdapterResultSet = $StorageAdapters->fetchByUniqueRoles(array('TEMP')); if (1 != count($tempStorageAdapterResultSet)) { throw new \RuntimeException("Fatal: exactly one storage adapter with role TEMP is required"); } $tempStorageAdapterSettings = array_pop($tempStorageAdapterResultSet); if ('FileSystemAdapter' != $tempStorageAdapterSettings['adapter_name']) { throw new \RuntimeException("Fatal: TEMP storage adapter: only FileSystemAdapter is currently supported by this script");
$supportedExtensions = ['jpg', 'jpeg', 'png', 'gif', 'psd', 'psf', 'tif', 'tiff']; out('Running script with the following supported extensions: ' . implode(', ', $supportedExtensions)); $db = \Directus\Bootstrap::get('ZendDb'); $acl = \Directus\Bootstrap::get('acl'); $Settings = new DirectusSettingsTableGateway($acl, $db); $filesSettings = $Settings->fetchCollection('media', ['thumbnail_size', 'thumbnail_quality', 'thumbnail_crop_enabled']); $StorageAdapters = new DirectusStorageAdaptersTableGateway($acl, $db); $storageAdaptersById = $StorageAdapters->fetchAllWithIdKeys(); foreach ($storageAdaptersById as $id => $storageAdapter) { $storageAdaptersById[$id] = \Directus\Files\Storage\Storage::getStorage($storageAdapter); } out('Loaded ' . count($storageAdaptersById) . ' storage adapters.'); $DirectusMedia = new TableGateway('directus_files', $db); $mediaRecords = $DirectusMedia->select(); out('Found ' . $mediaRecords->count() . ' Directus media records.'); $thumbnailStorageAdapterResultSet = $StorageAdapters->fetchByUniqueRoles(['THUMBNAIL']); if (1 != count($thumbnailStorageAdapterResultSet)) { throw new \RuntimeException('Fatal: exactly one storage adapter with role THUMBNAIL is required'); } $thumbnailStorageAdapterSettings = array_pop($thumbnailStorageAdapterResultSet); if ('FileSystemAdapter' != $thumbnailStorageAdapterSettings['adapter_name']) { throw new \RuntimeException('Fatal: THUMBNAIL storage adapter: only FileSystemAdapter is currently supported by this script'); } $thumbnailStorageAdapter = $storageAdaptersById[$thumbnailStorageAdapterSettings['id']]; $statistics = ['success' => 0, 'failure' => 0, 'exists' => 0]; foreach ($mediaRecords as $media) { if (!isset($storageAdaptersById[$media['storage_adapter']])) { throw new \RuntimeException('Files record #' . $media['id'] . ' refers to non-existent storage adapter #' . $media['storage_adapter']); } $storageAdapter = $storageAdaptersById[1]; $adapterSettings = $storageAdapter->getSettings();