/** * storeFiles move the files from incomming folder to file storage * @param array $p [ //upload params * files property - array of uploaded files, * response - response from user when asked about overwrite for single or many file * ] */ public function storeFiles(&$p) { /* here we'll iterate all files and comparing the md5 with already contained files will upload only new contents to our store. Existent contents will be reused */ foreach ($p['files'] as &$f) { if ($f['error'] == UPLOAD_ERR_NO_FILE) { continue; } if ($f['error'] !== UPLOAD_ERR_OK) { continue; } //apply general properties from $p to $f (file) variable foreach ($p as $k => $v) { if (in_array($k, array('id', 'pid', 'draftPid', 'name', 'title', 'content_id', 'template_id', 'cid', 'oid', 'data'))) { $f[$k] = $v; } } @($f['date'] = Util\dateISOToMysql($p['date'])); if (empty($f['template_id'])) { $f['template_id'] = Config::get('default_file_template'); } $this->storeContent($f); $pid = $p['pid']; if (!empty($f['dir'])) { $pid = $this->mkTreeDir($pid, $f['dir']); $f['pid'] = $pid; } $fileId = empty($p['id']) ? $this->getFileId($pid, $f['name']) : intval($p['id']); if (!empty($fileId)) { //newversion, replace, rename, autorename, cancel switch (@$p['response']) { case 'newversion': // case 'overwrite': // case 'overwriteall': $this->saveCurrentVersion($fileId); break; case 'replace': /* TODO: only mark file as deleted but dont delte it Note: we cant leave the previous file record if we have a given id for file */ DM\Tree::delete($fileId, true); $solr = new Solr\Client(); $solr->deleteByQuery('id:' . $fileId . ' OR pids: ' . $fileId); break; case 'rename': $fileId = null; $f['name'] = $p['newName']; //here is the new name break; case 'autorename': $fileId = null; $f['name'] = Objects::getAvailableName($pid, $f['name']); break; } } $f['type'] = 5; //file //save file $fileObject = new Objects\File(); if (!empty($fileId)) { $f['id'] = $fileId; if (@$p['response'] == 'replace') { $fileObject->create($f); } else { $fileObject->update($f); } } else { $f['id'] = $fileObject->create($f); } $this->updateFileProperties($f); } return true; }