19 declare(strict_types=1);
35 private \ilResourceStorageMigrationHelper
$helper;
42 return "Migration of Tile Images to the Resource Storage Service.";
52 return \ilResourceStorageMigrationHelper::getPreconditions();
57 $this->helper = new \ilResourceStorageMigrationHelper(
62 $this->flavour_builder = $this->helper->getFlavourBuilder();
68 $query_select = $this->helper->getDatabase()->query(
' 71 cs.value AS extension, 73 FROM container_settings AS cs 74 INNER JOIN object_data AS o 76 WHERE cs.keyword = "tile_image" 80 $next_record = $this->helper->getDatabase()->fetchObject($query_select);
82 if ($next_record === null) {
89 if (is_readable(dirname(dirname(
$path)))
90 && (!file_exists(dirname(
$path))
91 || is_readable(dirname(
$path)) && !file_exists(
$path))) {
93 $this->admin_interaction->inform(
94 "The tile image for the object with the id {$next_record->id} and the path {$path} " 95 .
'could not be migrated. The entry linking the image to the object ' 96 .
'was removed, the path to the image has been left on the system.' 101 $rid = $this->helper->movePathToStorage(
108 $this->admin_interaction->inform(
109 "The tile image for the object with the id {$next_record->id} and the path {$path} " 110 .
'could not be migrated. The database entry linking the image to the object ' 111 .
'was removed, the path to the image has been left on the system.' 115 $this->flavour_builder->get($rid, $this->flavour_definition,
true);
117 $this->helper->getDatabase()->update(
119 [
'tile_image_rid' => [
'text', $rid->serialize()]],
120 [
'obj_id' => [
'integer', $next_record->id],]
129 if (!is_dir($directory)) {
133 $files = array_diff(scandir($directory), [
'.',
'..']);
137 $file_list = implode(
', ', $files);
138 $this->admin_interaction->inform(
139 "The tile image for the object with the id $record->id was probably migrated successfully. " 140 .
"However, the directory $directory could not be removed because it is not empty. " 141 .
"Remaining files: $file_list. " 142 .
'You may want to verify that the tile image is visible for the object, and remove ' 143 .
'the remaining files manually if they are not needed.' 148 private function getFullPath(
int $object_id, ?
string $extension): string
156 'tile_image_' . $object_id,
157 'tile_image.' . $extension
164 $select_next_id = $this->helper->getDatabase()->query(
' 168 FROM container_settings 169 WHERE keyword = "tile_image" 173 $next_record = $this->helper->getDatabase()->fetchObject($select_next_id);
175 if ($next_record === null) {
179 $check_object_query = $this->helper->getDatabase()->queryF(
181 count(obj_id) AS objs 188 $has_objects = $this->helper->getDatabase()->fetchObject($check_object_query);
191 if ($has_objects->objs > 0) {
195 if (is_file(
$path)) {
205 $query_delete = $this->helper->getDatabase()->queryF(
' 206 DELETE FROM container_settings 207 WHERE keyword = "tile_image" AND id = %s 208 ', [
'integer'], [$id]);
209 $this->helper->getDatabase()->execute($query_delete);
214 $query = $this->helper->getDatabase()->query(
' 216 count(container_settings.id) AS amount 217 FROM container_settings 218 WHERE container_settings.keyword = "tile_image" 220 $r = $this->helper->getDatabase()->fetchObject($query);
222 return (
int)
$r->amount;
getFullPath(int $object_id, ?string $extension)
A migration is a potentially long lasting operation that can be broken into discrete steps...
ilResourceStorageMigrationHelper $helper
FlavourBuilder $flavour_builder
This defines ways in which objectives may interact with admins during the setup.
ilObjectTileImageFlavourDefinition $flavour_definition
cleanupTileInformationWithoutCorrespondingObject()
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
prepare(Environment $environment)
Prepare the migration by means of some environment.
getDefaultAmountOfStepsPerRun()
Tell the default amount of steps to be executed for one run of the migration.
getPreconditions(Environment $environment)
Objectives the migration depend on.
step(Environment $environment)
Run one step of the migration.
getRemainingAmountOfSteps()
Count up how many "things" need to be migrated.
An environment holds resources to be used in the setup process.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
const RESOURCE_ADMIN_INTERACTION
deleteTileImageInfoFromContainerSettings(int $id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
removeDirectoryOrInform(string $directory, \stdClass $record)
AdminInteraction $admin_interaction