/** * @param bool $forceRegen * @return Result\Delete * @throws FREST\Exception */ public function generateResult($forceRegen = FALSE) { $this->frest->startTimingForLabel(Type\Timing::PROCESSING, 'delete'); $otherResult = parent::generateResult($forceRegen); if (isset($otherResult)) { return $otherResult; } $pdo = $this->frest->getConfig()->getPDO(); /** @var Setting\Field $idFieldSetting */ $this->resource->getIDField($idFieldSetting); $isPerformingTransaction = FALSE; if (count($this->tableDeleteSpecs) > 1) { $pdo->beginTransaction(); $isPerformingTransaction = TRUE; } $this->frest->stopTimingForLabel(Type\Timing::PROCESSING, 'delete'); /** @var Spec\TableDelete $tableDeleteSpec */ foreach ($this->tableDeleteSpecs as $tableDeleteSpec) { $table = $tableDeleteSpec->getTable(); $idFieldName = $this->resource->getIDFieldForTable($table); $this->frest->startTimingForLabel(Type\Timing::SQL, 'delete'); $sql = "DELETE FROM {$table} WHERE {$idFieldName} = :_id"; $deleteStmt = $pdo->prepare($sql); $deleteStmt->bindValue(':_id', $this->resourceID, Type\Variable::pdoTypeFromVariableType($idFieldSetting->getVariableType())); if (!$deleteStmt->execute()) { if ($isPerformingTransaction) { $pdo->rollBack(); } throw new FREST\Exception(FREST\Exception::SQLError, 'Error deleting from database'); } $this->frest->stopTimingForLabel(Type\Timing::SQL, 'delete'); } $this->frest->startTimingForLabel(Type\Timing::SQL, 'delete'); if ($isPerformingTransaction) { $pdo->commit(); } $this->frest->stopTimingForLabel(Type\Timing::SQL, 'delete'); $this->result = new Result\Delete(); return $this->result; }
/** * @param $parameter * @param $value * @return bool * @throws FREST\Exception */ protected function isValidURLParameter($parameter, $value) { /** @noinspection PhpUndefinedClassInspection */ $isValid = parent::isValidURLParameter($parameter, $value); if (!$isValid) { // if not already determined to be valid $createSettings = $this->resource->getCreateSettings(); if (isset($createSettings[$parameter])) { /** @var Setting\Create $createSetting */ $createSetting = $createSettings[$parameter]; $fieldSetting = $this->resource->getFieldSettingForAlias($createSetting->getAlias()); if (!isset($fieldSetting)) { throw new FREST\Exception(FREST\Exception::Config, "No field setting found for condition '{$parameter}' in resource {$this->resource->getName()}"); } $isValid = TRUE; } } return $isValid; }
/** * @param $parameter * @param $value * * @return bool * @throws FREST\Exception */ protected function isValidURLParameter($parameter, $value) { /** @noinspection PhpUndefinedClassInspection */ $isValid = parent::isValidURLParameter($parameter, $value); // if not already determined valid if (!$isValid) { if ($parameter == 'fields') { if (!$this->getWasInternallyLoaded()) { if (!$this->resource->getAllowFieldsParameter()) { throw new FREST\Exception(FREST\Exception::FieldsParameterNotAllowed); } if (!$this->resource->getAllowPartialSyntax() && (strpos($value, '{') !== FALSE || strpos($value, '}') !== FALSE)) { throw new FREST\Exception(FREST\Exception::PartialSyntaxNotAllowed); } } $isValid = TRUE; } } return $isValid; }