Exemple #1
0
 /**
  * merge files
  * To be reviewed
  *
  * @param  int  $ids
  * @return json response
  */
 public function merge($ids)
 {
     if (!is_array($ids)) {
         return array('success' => false);
     }
     $ids = Util\toNumericArray($ids);
     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');
     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);
     $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);
     DB\dbQuery('UPDATE tree
         SET did = $2
                 , dstatus = 1
                 , updated = (updated | 1)
         WHERE id <> $1
             AND id IN (' . implode(', ', $ids) . ')', array($to_id, User::getId()));
     DM\Tree::update(array('id' => $to_id, 'updated' => 1));
     $ids = array_diff($ids, array($to_id));
     // Objects::updateCaseUpdateInfo($id);
     Solr\Client::runCron();
     return array('success' => true, 'rez' => $ids);
 }
Exemple #2
0
 /**
  * setting security inheritance flag for an item
  *
  * @param array $p {
  *     @type int      $id    id of tree node
  *     @type boolean  $inherit    set inherit to true or false
  *     @type string   $copyRules   when removing inheritance ($inherit = false)
  *                                 then this value could be set to 'yes' or 'no'
  *                                 for copying inherited rules to current node
  * }
  *
  */
 public function setInheritance($p)
 {
     /* check input params */
     if (empty($p['id']) || !isset($p['inherit']) || !is_numeric($p['id']) || !is_bool($p['inherit'])) {
         throw new \Exception(L\get('Wrong_input_data'));
     }
     /* end of check input params */
     if (!Security::isAdmin() && !Security::canChangePermissions($p['id'])) {
         throw new \Exception(L\get('Access_denied'));
     }
     /* checking if current inherit value is not already set to requested state */
     $inherit_acl = false;
     $r = DM\Tree::read($p['id']);
     if (!empty($r)) {
         $inherit_acl = $r['inherit_acl'];
     } else {
         throw new \Exception(L\get('Object_not_found'));
     }
     if ($inherit_acl == $p['inherit']) {
         return array('success' => false);
     }
     /* end of checking if current inherit value is not already set to requested state */
     // make pre update changes
     if ($p['inherit']) {
         DB\dbQuery('DELETE from tree_acl WHERE node_id = $1', $p['id']);
     } else {
         switch (@$p['copyRules']) {
             case 'yes':
                 //copy all inherited rules to current object
                 $acl = $this->getObjectAcl($p);
                 foreach ($acl['data'] as $rule) {
                     $allow = explode(',', str_replace('2', '1', $rule['allow']));
                     $deny = explode(',', str_replace('2', '1', $rule['deny']));
                     for ($i = 0; $i < 12; $i++) {
                         $allow[$i] = $allow[$i] == 1 ? '1' : '0';
                         $deny[$i] = $deny[$i] == -1 ? '1' : '0';
                     }
                     $allow = array_reverse($allow);
                     $deny = array_reverse($deny);
                     $allow = bindec(implode('', $allow));
                     $deny = bindec(implode('', $deny));
                     DB\dbQuery('INSERT INTO tree_acl (
                             node_id
                             ,user_group_id
                             ,allow
                             ,deny
                             ,cid)
                         VALUES($1
                              ,$2
                              ,$3
                              ,$4
                              ,$5) ON duplicate KEY
                         UPDATE allow = $3
                                 ,deny = $4
                                 ,uid = $5
                                 ,udate = CURRENT_TIMESTAMP', array($p['id'], $rule['id'], $allow, $deny, User::getId()));
                 }
                 break;
             default:
                 DB\dbQuery('DELETE from tree_acl WHERE node_id = $1', $p['id']);
                 break;
         }
     }
     // updating inherit flag for the object
     DM\Tree::update(array('id' => $p['id'], 'inherit_acl' => intval($p['inherit'])));
     Security::calculateUpdatedSecuritySets();
     Solr\Client::runBackgroundCron();
     return array('success' => true, 'data' => array());
 }
Exemple #3
0
 /**
  * move an object to $pid or over $targetId
  *
  * we'll use the same principle as for copy
  *
  * @param  int $pid      if not specified then will be set to pid of targetId
  * @param  int $targetId
  * @return int the id of moved object or false
  */
 public function moveTo($pid = false, $targetId = false)
 {
     // check input params
     if (!is_numeric($this->id) || !is_numeric($pid) && !is_numeric($targetId)) {
         return false;
     }
     /* security check */
     if (!\CB\Security::canRead($this->id)) {
         return false;
     }
     /* end of security check */
     //load current object from db into a variable to be passed to log and events
     $this->oldObject = clone $this;
     $this->oldObject->load($this->id);
     if (is_numeric($targetId)) {
         /* target security check */
         if (!\CB\Security::canWrite($targetId)) {
             return false;
         }
         /* end of target security check */
         // marking overwriten object with dstatus = 3
         DM\Tree::update(array('id' => $targetId, 'updated' => 1, 'dstatus' => 3, 'did' => User::getId()));
         $r = DM\Tree::read($targetId);
         if (!empty($r)) {
             $pid = $r['pid'];
         }
     } else {
         /* pid security check */
         if (!\CB\Security::canWrite($pid)) {
             return false;
         }
         /* end of pid security check */
     }
     /* check again if we have pid set
            It can be unset when not existent $targetId is specified
        */
     if (!is_numeric($pid)) {
         return false;
     }
     // moving the object to $pid
     DM\Tree::update(array('id' => $this->id, 'pid' => $pid, 'updated' => 1));
     $this->moveCustomDataTo($pid);
     // move childs from overwriten targetId (which has been marked with dstatus = 3)
     // to newly copied object
     if (is_numeric($targetId)) {
         DM\Tree::moveActiveChildren($targetId, $this->id);
     }
     $this->load();
     $this->logAction('move', array('old' => $this->oldObject));
     return $this->id;
 }
Exemple #4
0
 /**
  * updates udate and uid for a case
  * @param  int  $caseOrCaseObjectId
  * @return void
  */
 public static function updateCaseUpdateInfo($caseOrCaseObjectId)
 {
     DM\Tree::update(array('id' => $caseOrCaseObjectId, 'uid' => User::getId(), 'udate' => 'CURRENT_TIMESTAMP'));
 }
Exemple #5
0
 public function rename($p)
 {
     $id = explode('/', $p['path']);
     $id = array_pop($id);
     $p['name'] = trim($p['name']);
     if (!is_numeric($id) || empty($p['name'])) {
         return array('success' => false);
     }
     /* check security access */
     if (!Security::canWrite($id)) {
         throw new \Exception(L\get('Access_denied'));
     }
     $p['name'] = Purify::filename($p['name']);
     $rez = array('success' => true, 'data' => array('id' => $id, 'pid' => null, 'newName' => $p['name']));
     $objectType = Objects::getType($id);
     if ($objectType == 'shortcut') {
         $r = DM\Tree::read($id);
         if (!empty($r['target_id'])) {
             $id = $r['target_id'];
             $objectType = Objects::getType($id);
         }
     }
     DM\Tree::update(array('id' => $id, 'name' => $p['name']));
     if ($objectType == 'file') {
         DM\Files::update(array('id' => $id, 'name' => $p['name']));
     }
     /*updating renamed document into solr directly (before runing background cron)
       so that it'll be displayed with new name without delay*/
     $solrClient = new Solr\Client();
     $solrClient->updateTree(array('id' => $id));
     //running background cron to index other nodes
     $solrClient->runBackgroundCron();
     $p['name'] = htmlspecialchars($p['name'], ENT_COMPAT);
     //get pid
     $r = DM\Tree::read($rez['data']['id']);
     if (!empty($r['pid'])) {
         $rez['data']['pid'] = $r['pid'];
     }
     return $rez;
 }