forked from ILIAS-eLearning/ILIAS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
409 additions
and
91 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
118 changes: 118 additions & 0 deletions
118
components/ILIAS/Export/classes/class.ilMyExportDBTest.php
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<?php | ||
|
||
use ILIAS\Filesystem\Filesystems; | ||
use ILIAS\ResourceStorage\Services as ResourcesStorageService; | ||
use ILIAS\Filesystem\Stream\Streams; | ||
use ILIAS\Filesystem\Util\Archive\Zip; | ||
use ILIAS\Filesystem\Util\Archive\ZipOptions; | ||
use ILIAS\ResourceStorage\Stakeholder\AbstractResourceStakeholder; | ||
use ILIAS\ResourceStorage\Identification\ResourceIdentification; | ||
|
||
class ilMyExportDBTest | ||
{ | ||
protected const TABLE_NAME = "dummy_test2"; | ||
|
||
protected ResourcesStorageService $irss; | ||
protected ilLogger $logger; | ||
protected ilDBInterface $db; | ||
protected Filesystems $filesystems; | ||
|
||
public function __construct() | ||
{ | ||
global $DIC; | ||
$this->irss = $DIC->resourceStorage(); | ||
$this->logger = $DIC->logger()->root(); | ||
$this->db = $DIC->database(); | ||
$this->filesystems = $DIC->filesystem(); | ||
$this->initRidReferenceTable(); | ||
} | ||
|
||
protected function initRidReferenceTable(): void | ||
{ | ||
if ($this->db->tableExists(self::TABLE_NAME)) { | ||
return; | ||
} | ||
$this->db->createTable(self::TABLE_NAME, [ | ||
'rid' => [ | ||
'type' => 'text', | ||
'length' => 64, | ||
'default' => '', | ||
'notnull' => true | ||
], | ||
'obj_id' => [ | ||
'type' => 'integer', | ||
'length' => 8, | ||
'default' => '', | ||
'notnull' => true | ||
], | ||
]); | ||
$this->db->addPrimaryKey(self::TABLE_NAME, ["rid"]); | ||
} | ||
|
||
public function saveRid(int $obj_id, string $rid): void | ||
{ | ||
$this->logger->debug("Storing resource: " . $rid); | ||
$this->db->insert(self::TABLE_NAME, [ | ||
"rid" => ["text",$rid], | ||
"obj_id" => ["integer",$obj_id], | ||
]); | ||
} | ||
|
||
public function removeRid(string $rid): void | ||
{ | ||
$this->logger->debug("Removing resource: " . $rid); | ||
$this->db->manipulate("DELETE FROM " . $this->db->quoteIdentifier(self::TABLE_NAME) . " WHERE rid = " . $this->db->quote($rid)); | ||
} | ||
|
||
public function getStakeHolder(?int $usr_id = null): AbstractResourceStakeholder | ||
{ | ||
return new class ($usr_id) extends AbstractResourceStakeholder { | ||
protected $lcl_usr_id; | ||
public function __construct(?int $lcl_usr_id = null) | ||
{ | ||
$this->lcl_usr_id = $lcl_usr_id; | ||
} | ||
public function getId(): string | ||
{ | ||
return "test_export"; | ||
} | ||
public function getOwnerOfNewResources(): int | ||
{ | ||
return $this->lcl_usr_id ?? 6; | ||
} | ||
}; | ||
} | ||
|
||
public function delete(): void | ||
{ | ||
$res = $this->db->query("SELECT rid FROM il_resource"); | ||
$resource_id_strs = []; | ||
while ($row = $res->fetchAssoc()) { | ||
$resource_id_strs[] = $row['rid']; | ||
} | ||
foreach ($resource_id_strs as $resource_id_str) { | ||
$rid = $this->irss->manageContainer()->find($resource_id_str); | ||
if (!is_null($rid)) { | ||
$this->irss->manageContainer()->remove($rid, $this->getStakeHolder()); | ||
} | ||
$this->logger->debug("Removed Resource: " . $resource_id_str); | ||
} | ||
} | ||
|
||
public function deleteAllResources(): void | ||
{ | ||
$res = $this->db->query("SELECT rid FROM " . self::TABLE_NAME); | ||
$resource_id_strs = []; | ||
while ($row = $res->fetchAssoc()) { | ||
$resource_id_strs[] = $row['rid']; | ||
} | ||
foreach ($resource_id_strs as $resource_id_str) { | ||
$rid = $this->irss->manageContainer()->find($resource_id_str); | ||
if (!is_null($rid)) { | ||
$this->irss->manageContainer()->remove($rid, $this->getStakeHolder()); | ||
} | ||
$this->removeRid($resource_id_str); | ||
$this->logger->debug("Removed Resource: " . $resource_id_str); | ||
} | ||
} | ||
} |
Oops, something went wrong.