public function editDelete($rel, $isFlipped, $stableAtom, $stableConcept, $modifiedAtom, $modifiedConcept, $source = 'User') { Notifications::addLog("editDelete({$rel}, " . var_export($isFlipped, true) . ", {$stableAtom}, {$stableConcept}, {$modifiedAtom}, {$modifiedConcept})", 'DATABASE'); try { // This function is under control of transaction check! if (!isset($this->transaction)) { $this->startTransaction(); } $stableAtom = $this->typeConversion($stableAtom, $stableConcept); $modifiedAtom = $this->typeConversion($modifiedAtom, $modifiedConcept); // Check if $rel, $srcConcept, $tgtConcept is a combination $srcConcept = $isFlipped ? $modifiedConcept : $stableConcept; $tgtConcept = $isFlipped ? $stableConcept : $modifiedConcept; $fullRelationSignature = Relation::isCombination($rel, $srcConcept, $tgtConcept); // Get table properties $table = Relation::getTable($fullRelationSignature); $srcCol = Relation::getSrcCol($fullRelationSignature); $tgtCol = Relation::getTgtCol($fullRelationSignature); // Determine which Col must be editited and which must be used in the WHERE statement $stableCol = $isFlipped ? $tgtCol : $srcCol; $modifiedCol = $isFlipped ? $srcCol : $tgtCol; // Escape atoms for use in query $modifiedAtomEsc = $this->escape($modifiedAtom); $stableAtomEsc = $this->escape($stableAtom); // Get database table information $tableStableColumnInfo = Relation::getTableColumnInfo($table, $stableCol); $tableModifiedColumnInfo = Relation::getTableColumnInfo($table, $modifiedCol); // If the modifiedCol can be set to null, we do an update if ($tableModifiedColumnInfo['null']) { $this->Exe("UPDATE `{$table}` SET `{$modifiedCol}` = NULL WHERE `{$stableCol}` = '{$stableAtomEsc}' AND `{$modifiedCol}` = '{$modifiedAtomEsc}'"); // Elseif the stableCol can be set to null, we do an update } elseif ($tableStableColumnInfo['null']) { $this->Exe("UPDATE `{$table}` SET `{$stableCol}` = NULL WHERE `{$stableCol}` = '{$stableAtomEsc}' AND `{$modifiedCol}` = '{$modifiedAtomEsc}'"); // Otherwise, binary table, so perform a delete } else { $this->Exe("DELETE FROM `{$table}` WHERE `{$stableCol}` = '{$stableAtomEsc}' AND `{$modifiedCol}` = '{$modifiedAtomEsc}'"); } $this->addAffectedRelations($fullRelationSignature); // add relation to affected relations. Needed for conjunct evaluation. Hooks::callHooks('postDatabaseDelete', get_defined_vars()); } catch (Exception $e) { // Catch exception and continue script Notifications::addError($e->getMessage()); } }
function OverwritePopulation($rArray, $relationName, $concept) { try { $database = Database::singleton(); $fullRelationSignature = Relation::isCombination($relationName, $concept, $concept); $table = Relation::getTable($fullRelationSignature); $srcCol = Relation::getSrcCol($fullRelationSignature); $tgtCol = Relation::getTgtCol($fullRelationSignature); $query = "TRUNCATE TABLE {$table}"; $database->Exe($query); foreach ($rArray as $src => $tgtArray) { foreach ($tgtArray as $tgt => $bool) { if ($bool) { $query = "INSERT INTO {$table} (`{$srcCol}`, `{$tgtCol}`) VALUES ('{$src}','{$tgt}')"; $database->Exe($query); } } } } catch (Exception $e) { throw new Exception('OverwritePopulation: ' . $e->getMessage(), 500); } }