本文整理汇总了PHP中Part::set_master_picture_attachement_id方法的典型用法代码示例。如果您正苦于以下问题:PHP Part::set_master_picture_attachement_id方法的具体用法?PHP Part::set_master_picture_attachement_id怎么用?PHP Part::set_master_picture_attachement_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Part
的用法示例。
在下文中一共展示了Part::set_master_picture_attachement_id方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: delete
/**
* @brief Delete this attachement from database (and the associated file from harddisc if desired)
*
* @note This method overrides the same-named method from the parent class.
*
* @param boolean $delete_from_hdd if true, and the associated file isn't used in other file records,
* the file will be deleted from harddisc drive too (!!)
*
* @throws Exception if the file exists and should be deleted, but cannot be deleted
* (maybe not enought permissions)
* @throws Exception if there was an error
*/
public function delete($delete_from_hdd = false)
{
$filename = $this->get_filename();
$must_file_delete = false;
if ($delete_from_hdd && strlen($filename) > 0) {
// we will delete the file only from HDD if there are no other "Attachement" objects with the same filename!
$attachements = Attachement::get_attachements_by_filename($this->database, $this->current_user, $this->log, $filename);
if (count($attachements) <= 1 && file_exists($filename)) {
// check if there are enought permissions to delete the file
if (!is_writable(dirname($filename))) {
throw new Exception('Die Datei "' . $filename . '" kann nicht gelöscht werden, ' . 'da im übergeordneten Ordner keine Schreibrechte vorhanden sind!');
}
// all OK, file must be deleted after deleting the database record successfully
$must_file_delete = true;
}
}
try {
$transaction_id = $this->database->begin_transaction();
// start transaction
// Set all "id_master_picture_attachement" in the table "parts" to NULL where the master picture is this attachement
$query = 'SELECT id from parts WHERE id_master_picture_attachement=?';
$query_data = $this->database->query($query, array($this->get_id()));
foreach ($query_data as $row) {
$part = new Part($this->database, $this->current_user, $this->log, $row['id']);
$part->set_master_picture_attachement_id(NULL);
}
$this->get_element()->set_attributes(array());
// save element attributes to update its "last_modified"
// Now we can delete the database record of this attachement
parent::delete();
// now delete the file (if desired)
if ($must_file_delete) {
if (!unlink($filename)) {
throw new Exception('Die Datei "' . $filename . '" kann nicht von der Festplatte gelöscht ' . "werden! \nÜberprüfen Sie, ob die nötigen Rechte vorhanden sind.");
}
}
$this->database->commit($transaction_id);
// commit transaction
} catch (Exception $e) {
$this->database->rollback();
// rollback transaction
// restore the settings from BEFORE the transaction
$this->reset_attributes();
throw new Exception("Der Dateianhang \"" . $this->get_name() . "\" konnte nicht entfernt werden!\nGrund: " . $e->getMessage());
}
}