Skip to content

Commit

Permalink
Improve delete instance.
Browse files Browse the repository at this point in the history
  • Loading branch information
srobotta committed Dec 5, 2024
1 parent 547dced commit b5f81d4
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions classes/repository/instance_repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ private static function get_strings(string $type, int $subratingid, int $instanc
$dbobj->string = $dboheader->string;
$dbobj->typeid = $dboheader->typeid;
$dbobj->foreignkey = $dboheader->foreignkey;
$dbobj->instanceid = $dboheader->instanceid;

$sortedstrings[$cachekey][$dbobj->languageid] = $dbobj;
}
Expand Down Expand Up @@ -471,19 +472,20 @@ public function delete(int $instanceid) {

$dbocategories = $DB->get_records(tables::INSTANCE_CATEGORY_TABLE, ["instanceid" => $instanceid]);
foreach ($dbocategories as $dbocategory) {
// Delete all strings.
$DB->delete_records(tables::LOCALIZED_STRING_TABLE, ["instanceid" => $instanceid]);

// Delete category criteria.
$dbocriteria = $DB->get_records(tables::INSTANCE_CRITERION_TABLE, ["categoryid" => $dbocategory->id]);
foreach ($dbocriteria as $dbocriterion) {
// Delete subratings.
$dbosubratings = $DB->delete_records(tables::INSTANCE_SUBRATING_TABLE, ["criterionid" => $dbocriterion->id]);
$DB->delete_records(tables::INSTANCE_SUBRATING_TABLE, ["criterionid" => $dbocriterion->id]);
}
$DB->delete_records(tables::INSTANCE_CRITERION_TABLE, ["categoryid" => $dbocategory->id]);
}

// Delete all strings.
$DB->delete_records(tables::LOCALIZED_STRING_TABLE, ["instanceid" => $instanceid]);
// Delete categories.
$DB->delete_records(tables::INSTANCE_CATEGORY_TABLE, ["instanceid" => $instanceid]);
// Delete the instance itself.
return $DB->delete_records(tables::INSTANCE_TABLE, ["id" => $instanceid]);
}

Expand Down

0 comments on commit b5f81d4

Please sign in to comment.