Directory should be created in the system before saving in the DB.

1.9.x
Julio Montoya 10 years ago
parent 6b9b7b5832
commit 448c456cca
  1. 146
      main/inc/lib/fileUpload.lib.php

@ -1518,100 +1518,102 @@ function create_unexisting_directory(
} }
if (!is_dir($base_work_dir.$systemFolderName)) { if (!is_dir($base_work_dir.$systemFolderName)) {
mkdir( $result = mkdir(
$base_work_dir.$systemFolderName, $base_work_dir.$systemFolderName,
api_get_permissions_for_new_directories(), api_get_permissions_for_new_directories(),
true true
); );
// Check if pathname already exists inside document table if ($result) {
$tbl_document = Database::get_course_table(TABLE_DOCUMENT);
$sql = "SELECT id, path FROM $tbl_document
WHERE
c_id = $course_id AND
(
path = '".$systemFolderName."'
)
";
$rs = Database::query($sql); // Check if pathname already exists inside document table
if (Database::num_rows($rs) == 0) { $tbl_document = Database::get_course_table(TABLE_DOCUMENT);
$sql = "SELECT id, path FROM $tbl_document
WHERE
c_id = $course_id AND
(
path = '" . $systemFolderName . "'
)
";
$document_id = add_document( $rs = Database::query($sql);
$_course, if (Database::num_rows($rs) == 0) {
$systemFolderName,
'folder',
0,
$title,
null,
0,
true,
$to_group_id
);
if ($document_id) { $document_id = add_document(
// Update document item_property $_course,
if (!empty($visibility)) { $systemFolderName,
'folder',
0,
$title,
null,
0,
true,
$to_group_id
);
$visibilities = array( if ($document_id) {
0 => 'invisible', // Update document item_property
1 => 'visible', if (!empty($visibility)) {
2 => 'delete'
); $visibilities = array(
api_item_property_update( 0 => 'invisible',
$_course, 1 => 'visible',
TOOL_DOCUMENT, 2 => 'delete'
$document_id, );
$visibilities[$visibility], api_item_property_update(
$user_id, $_course,
$to_group_id, TOOL_DOCUMENT,
$to_user_id, $document_id,
null, $visibilities[$visibility],
null, $user_id,
$session_id $to_group_id,
); $to_user_id,
} else { null,
api_item_property_update( null,
$_course, $session_id
TOOL_DOCUMENT, );
} else {
api_item_property_update(
$_course,
TOOL_DOCUMENT,
$document_id,
'FolderCreated',
$user_id,
$to_group_id,
$to_user_id,
null,
null,
$session_id
);
}
$documentData = DocumentManager::get_document_data_by_id(
$document_id, $document_id,
'FolderCreated', $_course['code'],
$user_id, false,
$to_group_id,
$to_user_id,
null,
null,
$session_id $session_id
); );
return $documentData;
} }
} else {
$document = Database::fetch_array($rs);
$documentData = DocumentManager::get_document_data_by_id( $documentData = DocumentManager::get_document_data_by_id(
$document_id, $document['id'],
$_course['code'], $_course['code'],
false, false,
$session_id $session_id
); );
return $documentData;
} else {
return false;
}
} else {
$document = Database::fetch_array($rs);
$documentData = DocumentManager::get_document_data_by_id(
$document['id'],
$_course['code'],
false,
$session_id
);
/* This means the folder NOT exist in the filesystem /* This means the folder NOT exist in the filesystem
(now this was created) but there is a record in the Database*/ (now this was created) but there is a record in the Database*/
return $documentData; return $documentData;
}
} }
} else {
return false;
} }
return false;
} }
/** /**

Loading…
Cancel
Save