Skip to content

Instantly share code, notes, and snippets.

@hissy
Last active September 30, 2019 04:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hissy/e430159ad151a6b5fe64b3a0ed5d32a0 to your computer and use it in GitHub Desktop.
Save hissy/e430159ad151a6b5fe64b3a0ed5d32a0 to your computer and use it in GitHub Desktop.
#concrete5 Bulk change storage location for entire file manager
<?php
use Concrete\Core\Entity\File\File;
use Concrete\Core\File\FileList;
use Concrete\Core\File\StorageLocation\StorageLocationFactory;
use Concrete\Core\Support\Facade\Facade;
$app = Facade::getFacadeApplication();
/** @var StorageLocationFactory $factory */
$factory = $app->make(StorageLocationFactory::class);
// $oldStorageLocation = $factory->fetchDefault();
$oldStorageLocationName = 'Old Storage Location Name';
$newStorageLocationName = 'New Storage Location Name';
$oldStorageLocation = $factory->fetchByName($oldStorageLocationName);
$newStorageLocation = $factory->fetchByName($newStorageLocationName);
if (!is_object($oldStorageLocation)) {
echo sprintf('Storage Location %s not found.', $oldStorageLocationName);
die();
}
if (!is_object($newStorageLocation)) {
echo sprintf('Storage Location %s not found.', $newStorageLocationName);
die();
}
$list = new FileList();
$list->ignorePermissions();
$list->filterByStorageLocation($oldStorageLocation);
$files = $list->getResults();
$count = 0;
/** @var File $file */
foreach ($files as $file) {
$file->setFileStorageLocation($newStorageLocation);
++$count;
}
echo sprintf('%d files moved to new storage location.', $count);
<?php
use Concrete\Core\File\StorageLocation\StorageLocationFactory;
use Concrete\Core\Support\Facade\Facade;
$app = Facade::getFacadeApplication();
/** @var StorageLocationFactory $factory */
$factory = $app->make(StorageLocationFactory::class);
$locations = $factory->fetchList();
foreach ($locations as $location) {
echo $location->getName();
echo PHP_EOL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment