public function approveFileSubmission($id) { $nexcloud = filedepot_nexcloud(); $query = db_query("SELECT * FROM {filedepot_filesubmissions} WHERE id=:fid", array('fid' => $id)); $rec = $query->fetchObject(); $newfid = 0; // @TODO: Check if there have been multiple submission requests for the same file and thus have same new version # if ($rec->version == 1) { $private_destination = "private://filedepot/{$rec->cid}/"; // Best to call file_prepare_directory() - even if you believe directory exists file_prepare_directory($private_destination, FILE_CREATE_DIRECTORY); $file = file_load($rec->drupal_fid); $private_uri = $private_destination . $rec->fname; $file = file_move($file, $private_uri, FILE_EXISTS_RENAME); // Get name of new file in case it was renamed after the file_move() list($scheme, $target) = explode('://', $file->uri, 2); $filename = str_replace("filedepot/{$rec->cid}/", '', $target); if (isset($rec->title) and !empty($rec->title)) { $filetitle = $rec->title; } else { $filetitle = $rec->fname; } // Load the node for the folder and then update the file usage table $nid = db_query("SELECT nid FROM {filedepot_categories} WHERE cid=:cid", array(':cid' => $rec->cid))->fetchField(); $node = node_load($nid); file_usage_add($file, 'filedepot', 'node', $node->nid); // Remove the record for the core file module from the file usage table file_usage_delete($file, 'file'); $query = db_insert('filedepot_files'); $query->fields(array('cid', 'fname', 'title', 'description', 'version', 'drupal_fid', 'size', 'mimetype', 'submitter', 'status', 'date', 'version_ctl', 'extension')); $query->values(array('cid' => $rec->cid, 'fname' => $filename, 'title' => $filetitle, 'description' => $rec->description, 'version' => $rec->version, 'drupal_fid' => $file->fid, 'size' => $file->filesize, 'mimetype' => $file->filemime, 'submitter' => $rec->submitter, 'status' => 1, 'date' => $rec->date, 'version_ctl' => $rec->version_ctl, 'extension' => $rec->extension)); $query->execute(); // Get fileid for the new file record $newfid = db_query_range("SELECT fid FROM {filedepot_files} WHERE cid=:cid AND submitter=:uid ORDER BY fid DESC", 0, 1, array(':cid' => $rec->cid, ':uid' => $rec->submitter))->fetchField(); $query = db_insert('filedepot_fileversions'); $query->fields(array('fid', 'fname', 'drupal_fid', 'version', 'notes', 'size', 'date', 'uid', 'status')); $query->values(array('fid' => $newfid, 'fname' => $filename, 'drupal_fid' => $file->fid, 'version' => 1, 'notes' => $rec->version_note, 'size' => $file->filesize, 'date' => time(), 'uid' => $rec->submitter, 'status' => 1)); $query->execute(); if (!empty($rec->tags) and $this->checkPermission($rec->cid, 'view', 0, FALSE)) { $nexcloud->update_tags($newfid, $rec->tags); } } if ($newfid > 0) { if ($rec->notify == 1) { filedepot_sendNotification($newfid, FILEDEPOT_NOTIFY_APPROVED); } db_delete('filedepot_filesubmissions')->condition('id', $id)->execute(); // 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; } }
function filedepot_updateFolderLastModified($id) { $last_modified_parentdate = 0; if (db_query("SELECT cid FROM {filedepot_categories} WHERE cid=:cid", array(':cid' => $id))->fetchField() > 0) { $q1 = db_query("SELECT cid FROM {filedepot_categories} WHERE pid=:cid ORDER BY folderorder ASC", array(':cid' => $id)); while ($A = $q1->fetchAssoc()) { $last_modified_date = 0; $q2 = db_query_range("SELECT date FROM {filedepot_files} WHERE cid=:cid ORDER BY date DESC", 0, 1, array(':cid' => $A['cid'])); $B = $q2->fetchAssoc(); if ($B['date'] > $last_modified_date) { $last_modified_date = $B['date']; } if (db_query("SELECT pid FROM {filedepot_categories} WHERE cid=:cid", array(':cid' => $A['cid']))->fetchField() > 0) { $latestdate = filedepot_updateFolderLastModified($A['cid']); if ($latestdate > $last_modified_date) { $last_modified_date = $latestdate; } } db_query("UPDATE {filedepot_categories} SET last_modified_date=:time WHERE cid=:cid", array(':time' => $last_modified_date, ':cid' => $A['cid'])); if ($last_modified_date > $last_modified_parentdate) { $last_modified_parentdate = $last_modified_date; } } db_query("UPDATE {filedepot_categories} SET last_modified_date=:time WHERE cid=:cid", array(':time' => $last_modified_parentdate, ':cid' => $id)); } $q4 = db_query("SELECT date FROM {filedepot_files} WHERE cid=:cid ORDER BY date DESC", array(':cid' => $id)); $C = $q4->fetchAssoc(); if ($C['date'] > $last_modified_parentdate) { $last_modified_parentdate = $C['date']; } db_query("UPDATE {filedepot_categories} SET last_modified_date=:time WHERE cid=:cid", array(':time' => $last_modified_parentdate, ':cid' => $id)); return $last_modified_parentdate; }