use Directus\Db\TableGateway\DirectusStorageAdaptersTableGateway; use Directus\Files\Thumbnail; use Zend\Db\TableGateway\TableGateway; require 'directusLoader.php'; function out($string) { echo "{$string}\n"; } $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"); }