Skip to content

Commit

Permalink
Badge: Don't execute initialization during IRSS migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
mjansenDatabay committed Dec 17, 2024
1 parent 8e3351a commit e52a439
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ public function getPreconditions(Environment $environment): array

public function prepare(Environment $environment): void
{
ilContext::init(ilContext::CONTEXT_CRON);
ilInitialisation::initILIAS();

$this->helper = new ilResourceStorageMigrationHelper(
new ilBadgeFileStakeholder(),
$environment
Expand All @@ -58,7 +55,7 @@ public function step(Environment $environment): void
{
$this->helper->getDatabase()->setLimit(1);
$res = $this->helper->getDatabase()->query(
"SELECT id, image, image_rid FROM " . self::TABLE_NAME . " WHERE image_rid IS NULL OR image_rid = ''"
'SELECT id, image, image_rid FROM ' . self::TABLE_NAME . " WHERE image_rid IS NULL OR image_rid = ''"
);
$row = $this->helper->getDatabase()->fetchObject($res);
if (!($row instanceof stdClass)) {
Expand Down Expand Up @@ -98,48 +95,45 @@ public function step(Environment $environment): void
}
}

private function getImagePath(
int $id,
string $image,
bool $a_full_path = true
): string {
if ($id) {
$exp = explode('.', $image);
$suffix = strtolower(array_pop($exp));

if ($a_full_path) {
return $this->getFilePath($id) . 'img' . $id . '.' . $suffix;
}

return 'img' . $id . '.' . $suffix;
}
private function getImagePath(int $id, string $image): string
{
$exp = explode('.', $image);
$suffix = strtolower(array_pop($exp));

return '';
return $this->getFilePath($id) . 'img' . $id . '.' . $suffix;
}

private function getFilePath(
int $a_id,
string $a_subdir = null
): string {
$storage = new ilFSStorageBadgeImageTemplate($a_id);
$storage->create();
$path = $storage->getAbsolutePath() . '/';

if ($a_subdir) {
$path .= $a_subdir . '/';
private function getFilePath(int $a_id): string
{
return ILIAS_ABSOLUTE_PATH . '/' . ILIAS_WEB_DIR . '/' . CLIENT_ID . '/sec/ilBadge/' . $this->createLegacyPathSegmentForBadgeTemplateId($a_id);
}

if (!is_dir($path)) {
mkdir($path);
private function createLegacyPathSegmentForBadgeTemplateId(int $id): string
{
$path = [];
$found = false;
$num = $id;
$path_string = '';
for ($i = 3; $i > 0; $i--) {
$factor = 100 ** $i;
if (($tmp = (int) ($num / $factor)) || $found) {
$path[] = $tmp;
$num %= $factor;
$found = true;
}
}

return $path;
if (count($path)) {
$path_string = (implode('/', $path) . '/');
}

return $path_string . 'badgetmpl_' . $id;
}

public function getRemainingAmountOfSteps(): int
{
$res = $this->helper->getDatabase()->query(
"SELECT COUNT(id) as amount FROM " . self::TABLE_NAME . " WHERE image_rid IS NULL OR image_rid = ''"
'SELECT COUNT(id) as amount FROM ' . self::TABLE_NAME . " WHERE image_rid IS NULL OR image_rid = ''"
);
$row = $this->helper->getDatabase()->fetchObject($res);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ public function getPreconditions(Environment $environment): array

public function prepare(Environment $environment): void
{
ilContext::init(ilContext::CONTEXT_CRON);
ilInitialisation::initILIAS();

$this->helper = new ilResourceStorageMigrationHelper(
new ilBadgeFileStakeholder(),
$environment
Expand All @@ -58,7 +55,7 @@ public function step(Environment $environment): void
{
$this->helper->getDatabase()->setLimit(1);
$res = $this->helper->getDatabase()->query(
"SELECT id, image, image_rid FROM " . self::TABLE_NAME . " WHERE image_rid IS NULL OR image_rid = ''"
'SELECT id, image, image_rid FROM ' . self::TABLE_NAME . " WHERE image_rid IS NULL OR image_rid = ''"
);
$row = $this->helper->getDatabase()->fetchObject($res);
if (!($row instanceof stdClass)) {
Expand Down Expand Up @@ -98,48 +95,45 @@ public function step(Environment $environment): void
}
}

private function getImagePath(
int $id,
string $image,
bool $a_full_path = true
): string {
if ($id) {
$exp = explode('.', $image);
$suffix = strtolower(array_pop($exp));

if ($a_full_path) {
return $this->getFilePath($id) . 'img' . $id . '.' . $suffix;
}

return 'img' . $id . '.' . $suffix;
}
private function getImagePath(int $id, string $image): string
{
$exp = explode('.', $image);
$suffix = strtolower(array_pop($exp));

return '';
return $this->getFilePath($id) . 'img' . $id . '.' . $suffix;
}

private function getFilePath(
int $a_id,
string $a_subdir = null
): string {
$storage = new ilFSStorageBadge($a_id);
$storage->create();
$path = $storage->getAbsolutePath() . '/';

if ($a_subdir) {
$path .= $a_subdir . '/';
private function getFilePath(int $a_id): string
{
return ILIAS_ABSOLUTE_PATH . '/' . ILIAS_WEB_DIR . '/' . CLIENT_ID . '/sec/ilBadge/' . $this->createLegacyPathSegmentForBadgeId($a_id);
}

if (!is_dir($path)) {
mkdir($path);
private function createLegacyPathSegmentForBadgeId(int $id): string
{
$path = [];
$found = false;
$num = $id;
$path_string = '';
for ($i = 3; $i > 0; $i--) {
$factor = 100 ** $i;
if (($tmp = (int) ($num / $factor)) || $found) {
$path[] = $tmp;
$num %= $factor;
$found = true;
}
}

return $path;
if (count($path)) {
$path_string = (implode('/', $path) . '/');
}

return $path_string . 'badge_' . $id;
}

public function getRemainingAmountOfSteps(): int
{
$res = $this->helper->getDatabase()->query(
"SELECT COUNT(id) as amount FROM " . self::TABLE_NAME . " WHERE image_rid IS NULL OR image_rid = ''"
'SELECT COUNT(id) as amount FROM ' . self::TABLE_NAME . " WHERE image_rid IS NULL OR image_rid = ''"
);
$row = $this->helper->getDatabase()->fetchObject($res);

Expand Down

0 comments on commit e52a439

Please sign in to comment.