/** * Updates a single Property within a data record with the new value given. * * @param $entity Atrox_Core_Data_Entity The data record to be updated * @param $propertyName String Name of the Property to be changed * @param $newValue Mixed The new value for the record's Property * @see Atrox/Core/Data/Atrox_Core_Data_Source#updateProperty($entity, $propertyName, $newValue) */ public function updateProperty(Atrox_Core_Data_Entity $entity, $propertyName, $newValue) { //TODO: this needs a unit test then implementing if (!is_numeric($id = $entity->getId())) { return false; } $property = $this->getProperty($propertyName); if (!$entity->beforeUpdate($entity)) { throw new Exception("beforeUpdate failed"); return false; } $connection = $this->getConnection(); $sql = $connection->parseField($propertyName) . "="; if ($property->getType() == Atrox_Core_Data_Property::TYPE_BINARY) { $binary = $entity->get($name); if ($this->hasFileError($binary["File"]["Error"])) { return false; } if (isset($binary["Remove"])) { $value = ""; } else { if ($binary["File"]["Error"] == 0) { $binary["Hash"] = $propertyName . "/" . md5(uniqid(null, true)); $value = $binary["Hash"] . "/" . $binary["File"]["Filename"]; } else { $value = $binary["Current"]; } } } else { $value = $property->formatForSourceInput($newValue); } if ($value === "" || $value === null) { $sql .= "null"; } else { $sql .= $connection->parseValue($value); } $sql = "UPDATE {$this->parsedTableName} SET {$sql} WHERE {$this->parsedIdName} = " . $entity->getId() . ";"; if (!$connection->query($sql)) { return false; } $this->serviceLocator->getCacheManager()->clear($this->getCacheKey($this->idName . ":" . $entity->getId())); if (isset($binary) && $binary) { $storageProvider = $this->serviceLocator->getStorageAdaptor(); if (isset($binary["Remove"])) { if ($binary["Current"] != "") { $this->deleteBinary($binary["Current"]); } } else { try { if ($binary["Current"] != "") { $this->deleteBinary($binary["Current"]); } $storageProvider->makeBucket($this->getTableName() . "/" . $binary["Hash"]); } catch (Exception $e) { } $storageProvider->putBinaryFile($binary["File"]["TempName"], $this->getTableName() . "/" . $binary["Hash"], $binary["File"]["Filename"], $binary["File"]["Type"]); } } if (!$entity->afterUpdate($entity)) { throw new Exception("afterUpdate failed"); return false; } }