Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Badge: Don't execute initialization during IRSS migrations #8741

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading