Last active
September 30, 2019 04:55
-
-
Save hissy/e430159ad151a6b5fe64b3a0ed5d32a0 to your computer and use it in GitHub Desktop.
#concrete5 Bulk change storage location for entire file manager
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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