Change delete document mechanism to use doc ID instead of path - refs BT#7128

1.9.x
Yannick Warnier 11 years ago
parent 87aea8fbee
commit 69bc79fd0c
  1. 8
      main/document/document.inc.php
  2. 13
      main/document/document.php
  3. 29
      main/inc/lib/document.lib.php

@ -591,19 +591,19 @@ function build_edit_icons($document_data, $id, $is_template, $is_read_only = 0,
$modify_icons .= ' ' . Display::return_icon('delete_na.png', get_lang('ThisFolderCannotBeDeleted'), array(), ICON_SIZE_SMALL);
} else {
if (isset($_GET['curdirpath']) && $_GET['curdirpath'] == '/certificates' && DocumentManager::get_default_certificate_id(api_get_course_id()) == $id) {
$modify_icons .= '&nbsp;<a href="' . api_get_self() . '?' . api_get_cidreq() . '&amp;curdirpath=' . $curdirpath . '&amp;delete=' . urlencode($path) . $req_gid . '&amp;' . $sort_params . 'delete_certificate_id=' . $id . '" onclick="return confirmation(\'' . basename($path) . '\');">' . Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>';
$modify_icons .= '&nbsp;<a href="' . api_get_self() . '?' . api_get_cidreq() . '&amp;curdirpath=' . $curdirpath . '&amp;deleteid=' . $document_id . $req_gid . '&amp;' . $sort_params . 'delete_certificate_id=' . $id . '" onclick="return confirmation(\'' . basename($path) . '\');">' . Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>';
} else {
if ($is_certificate_mode) {
$modify_icons .= '&nbsp;<a href="' . api_get_self() . '?' . api_get_cidreq() . '&amp;curdirpath=' . $curdirpath . '&amp;delete=' . urlencode($path) . $req_gid . '&amp;' . $sort_params . '" onclick="return confirmation(\'' . basename($path) . '\');">' . Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>';
$modify_icons .= '&nbsp;<a href="' . api_get_self() . '?' . api_get_cidreq() . '&amp;curdirpath=' . $curdirpath . '&amp;deleteid=' . $document_id . $req_gid . '&amp;' . $sort_params . '" onclick="return confirmation(\'' . basename($path) . '\');">' . Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>';
} else {
if (api_get_session_id()) {
if ($document_data['session_id'] == api_get_session_id()) {
$modify_icons .= '&nbsp;<a href="' . api_get_self() . '?' . api_get_cidreq() . '&amp;curdirpath=' . $curdirpath . '&amp;delete=' . urlencode($path) . $req_gid . '&amp;' . $sort_params . '" onclick="return confirmation(\'' . basename($path) . '\');">' . Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>';
$modify_icons .= '&nbsp;<a href="' . api_get_self() . '?' . api_get_cidreq() . '&amp;curdirpath=' . $curdirpath . '&amp;deleteid=' . $document_id . $req_gid . '&amp;' . $sort_params . '" onclick="return confirmation(\'' . basename($path) . '\');">' . Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>';
} else {
$modify_icons .= '&nbsp;' . Display::return_icon('delete_na.png', get_lang('ThisFolderCannotBeDeleted'), array(), ICON_SIZE_SMALL);
}
} else {
$modify_icons .= '&nbsp;<a href="' . api_get_self() . '?' . api_get_cidreq() . '&amp;curdirpath=' . $curdirpath . '&amp;delete=' . urlencode($path) . $req_gid . '&amp;' . $sort_params . '" onclick="return confirmation(\'' . basename($path) . '\');">' . Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>';
$modify_icons .= '&nbsp;<a href="' . api_get_self() . '?' . api_get_cidreq() . '&amp;curdirpath=' . $curdirpath . '&amp;deleteid=' . $document_id . $req_gid . '&amp;' . $sort_params . '" onclick="return confirmation(\'' . basename($path) . '\');">' . Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>';
}
}
}

@ -666,27 +666,28 @@ if (
/* DELETE FILE OR DIRECTORY */
//Only teacher and all users into their group
if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder(api_get_user_id(), $curdirpath, $session_id)) {
if (isset($_GET['delete'])) {
if (isset($_GET['deleteid'])) {
if (!$is_allowed_to_edit) {
if (api_is_coach()) {
if (!DocumentManager::is_visible($_GET['delete'], $_course, $session_id)) {
if (!DocumentManager::is_visible_by_id($_GET['deleteid'], $_course, $session_id, api_get_user_id())) {
api_not_allowed();
}
}
if (DocumentManager::check_readonly($_course, api_get_user_id(), $_GET['delete'], '', true)) {
if (DocumentManager::check_readonly($_course, api_get_user_id(), '', $_GET['deleteid'], true)) {
api_not_allowed();
}
}
$document_data = DocumentManager::get_document_id($_course, $_GET['delete']);
$document_data = intval($_GET['deleteid']);
$documentInfo = DocumentManager::get_document_data_by_id($_GET['deleteid'], $_course['code'], false, $session_id);
// Check whether the document is in the database
if (!empty($document_data)) {
if (DocumentManager::delete_document($_course, $_GET['delete'], $base_work_dir)) {
if (DocumentManager::delete_document($_course, null, $base_work_dir, api_get_session_id(), $_GET['deleteid'])) {
$certificateId = isset($_GET['delete_certificate_id']) ? $_GET['delete_certificate_id'] : null;
DocumentManager::remove_attach_certificate(api_get_course_id(), $certificateId);
Display::display_confirmation_message(get_lang('DocDeleted'));
} else {
Display::display_error_message(get_lang('DocDeleteError'));
Display::display_warning_message(get_lang('DocDeleteError'));
}
} else {
Display::display_warning_message(get_lang('FileNotFound'));

@ -780,8 +780,10 @@ class DocumentManager
$sessionId = intval($sessionId);
}
if (!(!empty($document_id) && is_numeric($document_id))) {
if (empty($document_id) || !is_numeric($document_id)) {
$document_id = self::get_document_id($_course, $file, $sessionId);
} else {
$document_id = intval($document_id);
}
$TABLE_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
@ -936,15 +938,25 @@ class DocumentManager
* @param array $_course
* @param string $path, path stored in the database
* @param string $base_work_dir, path to the documents folder
* @param int $sessionId The ID of the session, if any
* @param int $documentId The document id, if available
* @return boolean true/false
* @todo now only files/folders in a folder get visibility 2, we should rename them too.
*/
public static function delete_document($_course, $path, $base_work_dir, $sessionId = null)
public static function delete_document($_course, $path = null, $base_work_dir, $sessionId = null, $documentId = null)
{
$TABLE_DOCUMENT = Database :: get_course_table(TABLE_DOCUMENT);
if (empty($path) || empty($base_work_dir)) {
return false;
// @todo We should be able to get rid of this later when using only documentId (check further usage)
if (empty ($documentId)) {
if (empty($path) || empty($base_work_dir)) {
return false;
}
} else {
if (empty($base_work_dir)) {
return false;
}
$docInfo = self::get_document_data_by_id($documentId, $_course['code'], false, $sessionId);
$path = $docInfo['path'];
}
$course_id = $_course['real_id'];
@ -960,7 +972,11 @@ class DocumentManager
}
// First, delete the actual document.
$document_id = self::get_document_id($_course, $path, $sessionId);
if (empty($documentId)) {
$document_id = self::get_document_id($_course, $path, $sessionId);
} else {
$document_id = intval($documentId);
}
if (empty($document_id)) {
return false;
@ -1045,6 +1061,7 @@ class DocumentManager
}
// Checking inconsistency
//error_log('Doc status: (1 del db :'.($file_deleted_from_db?'yes':'no').') - (2 del disk: '.($file_deleted_from_disk?'yes':'no').') - (3 ren disk: '.($file_renamed_from_disk?'yes':'no').')');
if ($file_deleted_from_db && $file_deleted_from_disk ||
$file_deleted_from_db && $file_renamed_from_disk
) {

Loading…
Cancel
Save