Beispiel #1
0
 public function deleteVersion($id)
 {
     $rez = array('success' => true, 'id' => $id);
     $content_id = 0;
     $version = DM\FilesVersions::read($id);
     if (!empty($version)) {
         $content_id = $version['content_id'];
     }
     DM\FilesVersions::delete($id);
     $this->removeContentId($content_id);
     DM\Tree::update(array('id' => $version['file_id'], 'updated' => 1));
     Objects::updateCaseUpdateInfo($id);
     Solr\Client::runCron();
     return $rez;
 }
Beispiel #2
0
 /**
  * save or create an object
  * @param  array $p object properties
  * @return json  responce
  */
 public function save($p)
 {
     $d = Util\toJSONArray($p['data']);
     // check if need to create object instead of update
     if (empty($d['id']) || !is_numeric($d['id'])) {
         return $this->create($d);
     }
     // SECURITY: check if current user has write access to this action
     if (!Security::canWrite($d['id'])) {
         throw new \Exception(L\get('Access_denied'));
     }
     /* prepare params */
     if (empty($d['date']) && !empty($d['date_start'])) {
         $d['date'] = $d['date_start'];
     }
     /* end of prepare params */
     // update object
     $object = $this->getCachedObject($d['id']);
     //set sys_data from object, it can contain custom data
     //that shouldn't be overwritten
     $d['sys_data'] = $object->getSysData();
     $object->update($d);
     Objects::updateCaseUpdateInfo($d['id']);
     /* updating saved document into solr directly (before runing background cron)
        so that it'll be displayed with new name without delay */
     if (!\CB\Config::getFlag('disableSolrIndexing')) {
         $solrClient = new Solr\Client();
         $solrClient->updateTree(array('id' => $d['id']));
         //running background cron to index other nodes
         $solrClient->runBackgroundCron();
     }
     return $this->load($d);
 }
Beispiel #3
0
 public function merge($ids)
 {
     if (!is_array($ids)) {
         return array('success' => false);
     }
     $ids = array_filter($ids, 'is_numeric');
     if (sizeof($ids) < 2) {
         return array('success' => false);
     }
     $to_id = null;
     $res = DB\dbQuery('SELECT id
         FROM tree
         WHERE id IN (' . implode(', ', $ids) . ')
         ORDER BY udate DESC, id DESC') or die(DB\dbQueryError());
     if ($r = $res->fetch_assoc()) {
         $to_id = $r['id'];
     }
     $res->close();
     DB\dbQuery('UPDATE files_versions
         SET file_id = $1
         WHERE file_id IN (' . implode(', ', $ids) . ')', $to_id) or die(DB\dbQueryError());
     $res = DB\dbQuery('INSERT INTO files_versions (file_id, content_id, `date`, name, cid, uid, cdate, udate)
             SELECT $1
                  , content_id
                  , `date`
                  , name
                  , cid
                  , uid
                  , cdate
                  , udate
             FROM files
             WHERE id <> $1
                 AND id in(' . implode(',', $ids) . ')', $to_id) or die(DB\dbQueryError());
     DB\dbQuery('UPDATE tree
         SET did = $2
                 , dstatus = 1
                 , updated = (updated | 1)
         WHERE id <> $1
             AND id IN (' . implode(', ', $ids) . ')', array($to_id, $_SESSION['user']['id'])) or die(DB\dbQueryError());
     DB\dbQuery('UPDATE tree
         SET updated = (updated | 1)
         WHERE id = $1', $to_id) or die(DB\dbQueryError());
     $ids = array_diff($ids, array($to_id));
     Objects::updateCaseUpdateInfo($id);
     Solr\Client::runCron();
     return array('success' => true, 'rez' => $ids);
 }
Beispiel #4
0
 /**
  * method called after a task have been updated
  * used now to update solr and cases date
  * @param  int  $taskId
  * @return void
  */
 protected function afterUpdate($taskId)
 {
     Objects::updateCaseUpdateInfo($taskId);
     $solr = new Solr\Client();
     $solr->updateTree(array('id' => $taskId));
 }