public function filedepot::approveFileSubmission in filedepot 6
Same name and namespace in other branches
- 7 filedepot.class.php \filedepot::approveFileSubmission()
File
- ./
filedepot.class.php, line 1088 - filedepot.class.php Main class for the Filedepot module
Class
- filedepot
- @file filedepot.class.php Main class for the Filedepot module
Code
public function approveFileSubmission($id) {
$nexcloud = filedepot_nexcloud();
$query = db_query("SELECT * FROM {filedepot_filesubmissions} WHERE id=%d", $id);
$rec = db_fetch_object($query);
$data = array();
// @TODO: Check if there have been multiple submission requests for the same file and thus have same new version #
if ($rec->version == 1) {
$curfile = "{$this->root_storage_path}{$rec->cid}/submissions/{$rec->tempname}";
$newfile = "{$this->root_storage_path}{$rec->cid}/{$rec->fname}";
$rename = @rename($curfile, $newfile);
// Need to update the filename path in the drupal files table
db_query("UPDATE {files} SET filename='%s', filepath='%s', filemime='%s' WHERE fid=%d", $rec->fname, $newfile, $rec->mimetype, $rec->cckfid);
$sql = "INSERT INTO {filedepot_files} (cid,fname,title,description,version,cckfid,size,mimetype,submitter,status,date,version_ctl,extension) " . "VALUES (%d,'%s','%s','%s',1,%d,%d,'%s',%d,1,%d,%d,'%s')";
db_query($sql, $rec->cid, $rec->fname, $rec->title, $rec->description, $rec->cckfid, $rec->size, $rec->mimetype, $rec->submitter, time(), $rec->version_ctl, $rec->extension);
// Get fileid for the new file record
$args = array(
$rec->cid,
$rec->submitter,
);
$newfid = db_result(db_query("SELECT fid FROM {filedepot_files} WHERE cid=%d AND submitter=%d ORDER BY fid DESC", $args, 0, 1));
db_query("INSERT INTO {filedepot_fileversions} (fid,cckfid,fname,version,notes,size,date,uid,status)\n VALUES (%d,%d,'%s','1','%s',%d,%d,%d,1)", $newfid, $rec->cckfid, $rec->fname, $rec->version_note, $rec->size, time(), $rec->submitter);
if (!empty($rec->tags) and $this
->checkPermission($rec->cid, 'view', 0, FALSE)) {
$nexcloud
->update_tags($fid, $rec->tags);
}
}
else {
// Need to rename the current versioned file
$curfile = "{$this->root_storage_path}{$rec->cid}/submissions/{$rec->tempname}";
$newfile = "{$this->root_storage_path}{$rec->cid}/{$rec->fname}";
$rename = @rename($curfile, $newfile);
db_query("INSERT INTO {filedepot_fileversions} (fid,cckfid,fname,version,notes,size,date,uid,status)\n VALUES (%d,%d,'%s','1','%s',%d,%d,%d,1)", $newfid, $rec->cckfid, $rec->fname, $rec->version_note, $rec->size, time(), $rec->submitter);
db_query("UPDATE {filedepot_files} SET fname='%s',version=%d, date=%d WHERE fid=%d", $rec->fname, $rc->version, time(), $rec->fid);
$newfid = $fid;
}
if ($newfid > 0) {
if ($rec->notify == 1) {
filedepot_sendNotification($newfid, FILEDEPOT_NOTIFY_APPROVED);
}
db_query("DELETE FROM {filedepot_filesubmissions} WHERE id=%d", $id);
// Send out notifications of update to all subscribed users
filedepot_sendNotification($newfid, FILEDEPOT_NOTIFY_NEWFILE);
// Update related folders last_modified_date
$workspaceParentFolder = filedepot_getTopLevelParent($rec->cid);
filedepot_updateFolderLastModified($workspaceParentFolder);
return TRUE;
}
else {
return FALSE;
}
}