/** * 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); }
/** * create shorcut(s) * @param object $p input params * @return json responce */ public function shortcut($p) { if (!$this->validateParams($p)) { return array('success' => false, 'msg' => L\get('ErroneousInputData')); } /* security checks */ foreach ($p['sourceIds'] as $sourceId) { if (!\CB\Security::canRead($sourceId)) { return array('success' => false, 'msg' => L\get('Access_denied')); } } if (!\CB\Security::canWrite($p['targetId'])) { return array('success' => false, 'msg' => L\get('Access_denied')); } $rez = array('success' => true, 'targetId' => $p['targetId'], 'processedIds' => array()); $shortcutObject = new Objects\Shortcut(); foreach ($p['sourceIds'] as $id) { $rez['processedIds'][] = $shortcutObject->create(array('id' => null, 'pid' => $p['targetId'], 'target_id' => $id)); } Solr\Client::runCron(); return $rez; }
/** * reindex solr core if needed * @return void */ protected function reindex() { $solr = new Solr\Client(); $solr->updateTree(array('all' => true, 'nolimit' => true)); }
/** * remove security rules from child items * * @param array json request * @return array json response */ public function removeChildPermissions($p) { if (!Security::isAdmin()) { throw new \Exception(L\get('Access_denied')); } $pids = Objects::getPids($p['id'], false); $pids = implode(',', $pids); $child_ids = array(); // selecting childs with accesses $res = DB\dbQuery('SELECT id FROM tree_info WHERE pids like $1 and acl_count > 0', $pids . ',%'); while ($r = $res->fetch_assoc()) { $child_ids[] = $r['id']; } $res->close(); //remove security rules for childs if (!empty($child_ids)) { DB\dbQuery('DELETE FROM tree_acl WHERE node_id in (' . implode(',', $child_ids) . ')'); // update inherit flag DB\dbQuery('UPDATE tree SET inherit_acl = 1 WHERE id in (' . implode(',', $child_ids) . ')'); } Solr\Client::runBackgroundCron(); return array('success' => true); }
/** * Save access data specified for a user in UserManagement form (groups association) * * */ public function saveAccessData($p) { if (!User::isVerified()) { return array('success' => false, 'verify' => true); } if (!Security::canManage()) { throw new \Exception(L\get('Access_denied')); } $p = (array) $p; @($user_id = $this->extractId($p['id'])); /* analize groups: - for newly associated groups the access should be updated - for deassociated groups the access also should be reviewed/**/ /* get current user groups */ $current_groups = UsersGroups::getGroupIdsForUser($user_id); $updating_groups = Util\toNumericArray(@$p['groups']); $new_groups = array_diff($updating_groups, $current_groups); $deleting_groups = array_diff($current_groups, $updating_groups); foreach ($new_groups as $group_id) { DB\dbQuery('INSERT INTO users_groups_association (user_id, group_id, cid) VALUES($1, $2, $3) ON DUPLICATE KEY UPDATE uid = $3', array($user_id, $group_id, $_SESSION['user']['id'])) or die(DB\dbQueryError()); } if (!empty($deleting_groups)) { DB\dbQuery('DELETE FROM users_groups_association WHERE user_id = $1 AND group_id IN (' . implode(', ', $deleting_groups) . ')', $user_id) or die(DB\dbQueryError()); } Security::calculateUpdatedSecuritySets($user_id); Solr\Client::runBackgroundCron(); return array('success' => true); }
/** * remove own comment * @param array $p input params (id) */ public function removeComment($p) { $rez = array('success' => false); if (empty($p['id']) || !is_numeric($p['id'])) { $rez['msg'] = L\get('Wrong_input_data'); return $rez; } $comment = static::getCustomClassByObjectId($p['id']); $commentData = $comment->load(); if ($commentData['cid'] == $_SESSION['user']['id']) { $comment->delete(); Solr\Client::runCron(); $rez['success'] = true; } return $rez; }
/** * 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)); }
public static function deleteObject($id) { $file = new \CB\Objects\Object($id); $file->delete(); \CB\Solr\Client::runCron(); }
public static function checkRootFolder() { $id = null; $res = DB\dbQuery('SELECT id FROM tree WHERE pid IS NULL AND `system` = 1 AND `is_main` = 1') or die(DB\dbQueryError()); if ($r = $res->fetch_assoc()) { $id = $r['id']; } $res->close(); /* create root folder */ if ($id == null) { DB\dbQuery('INSERT INTO tree (`system` , `name` , is_main , updated , template_id) VALUES (1 ,\'root\' ,1 ,1 ,$1)', Config::get('default_folder_template')) or die(DB\dbQueryError()); $id = DB\dbLastInsertId(); Solr\Client::runCron(); } return $id; }
/** * get email folder id for specified user id. If folder does not exist it is created automaticly. * @param int $user_id * @return int email folder id */ public static function getEmailFolderId($user_id = false) { $rez = null; if (empty($user_id)) { $user_id = $_SESSION['user']['id']; } $pid = User::getUserHomeFolderId($user_id); $res = DB\dbQuery('SELECT id FROM tree WHERE user_id = $1 AND SYSTEM = 1 AND pid =$2 AND type = 1', array($_SESSION['user']['id'], $pid)) or die(DB\dbQueryError()); if ($r = $res->fetch_assoc()) { $rez = $r['id']; } $res->close(); if (empty($rez)) { DB\dbQuery('INSERT INTO tree ( pid ,user_id ,`system` ,`type` ,`name` ,cid ,uid ,template_id) VALUES ( $1 ,$2 ,1 ,1 ,\'[Emails]\' ,$3 ,$3 ,$4)', array($pid, $user_id, $_SESSION['user']['id'], Config::get('default_folder_template'))) or die(DB\dbQueryError()); $rez = DB\dbLastInsertId(); Solr\Client::runCron(); } return $rez; }
public function confirmUploadRequest($p) { //if cancel then delete all uploaded files from incomming $files = new Files(); $a = $files->getUploadParams(); $a['response'] = $p['response']; switch ($p['response']) { case 'rename': $a['newName'] = Purify::filename($p['newName']); //check if the new name does not also exist if (empty($a['response'])) { return array('success' => false, 'msg' => L\get('FilenameCannotBeEmpty')); } reset($a['files']); $k = key($a['files']); $a['files'][$k]['name'] = $a['newName']; if ($files->fileExists($a['pid'], $a['newName'])) { $files->saveUploadParams($a); return array('success' => false, 'type' => 'filesexist', 'allow_new_version' => Files::getMFVC($a['newName']) > 0, 'suggestedFilename' => Objects::getAvailableName($a['pid'], $a['newName']), 'msg' => str_replace('{filename}', '"' . $a['newName'] . '"', L\get('FilenameExistsInTarget'))); } // $files->storeFiles($a); // break; // $files->storeFiles($a); // break; case 'newversion': case 'replace': case 'autorename': $files->storeFiles($a); break; default: //cancel $files->removeIncomingFiles($a['files']); return array('success' => true, 'data' => array()); break; } Solr\Client::runCron(); $rez = array('success' => true, 'data' => array('pid' => $a['pid'])); $files->attachPostUploadInfo($a['files'], $rez); return $rez; }