예제 #1
0
 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;
     }
 }
예제 #2
0
function filedepot_getTopLevelParent($cid)
{
    $pid = db_query("SELECT pid FROM {filedepot_categories} WHERE cid=:cid", array(':cid' => $cid))->fetchField();
    if ($pid == 0) {
        return $cid;
    } else {
        $cid = filedepot_getTopLevelParent($pid);
    }
    return $cid;
}