Example #1
0
 /**
  * start importing process
  * @return void
  */
 public function import()
 {
     \CB\Config::setFlag('disableSolrIndexing', true);
     \CB\Config::setFlag('disableActivityLog', true);
     \CB\Config::setFlag('disableTriggers', true);
     DB\startTransaction();
     echo "\nInitializing .. \n____________________________\n";
     $this->init();
     echo "\nOk\n";
     echo "\nPreparing .. \n____________________________\n";
     $this->prepare();
     echo "\nOk\n";
     echo "\nExecuting .. \n____________________________\n";
     $this->execute();
     echo "\nOk\n";
     echo "\nAdjusting .. \n____________________________\n";
     $this->adjust();
     echo "\nOk\n";
     \CB\Config::setFlag('disableTriggers', false);
     \CB\Config::setFlag('disableActivityLog', false);
     \CB\Config::setFlag('disableSolrIndexing', false);
     DB\commitTransaction();
     echo "\nReindexing .. \n____________________________\n";
     $this->reindex();
     echo "\nOk\n";
 }
Example #2
0
 /**
  * internal function executing a copy or move action
  * @param  array $sourceIds ids to be copied
  * @param  int   $targetId
  * @return array processed ids
  */
 private function doAction($action, $objectIds, $targetId)
 {
     $rez = array();
     // all the copy process will be made in a single transaction
     DB\startTransaction();
     //get security sets to which this user has
     //read access for copy or delete access for move
     $this->securitySetsFilter = '';
     if (!Security::isAdmin()) {
         $ss = array();
         switch ($action) {
             case 'copy':
                 $ss = \CB\Security::getSecuritySets();
                 break;
             case 'move':
                 //check if the user can move, because it doesnt anctually delete the obj, but just move it
                 $ss = \CB\Security::getSecuritySets(false, 5);
                 break;
         }
         $this->securitySetsFilter = 'AND ti.security_set_id in (0' . implode(',', $ss) . ')';
     }
     /* select only objects that current user can delete */
     $accessibleIds = array();
     $res = DB\dbQuery('SELECT t.id
         FROM tree t
         JOIN tree_info ti ON
             t.id = ti.id ' . $this->securitySetsFilter . '
         WHERE t.id in (' . implode(',', $objectIds) . ')
             AND t.dstatus = 0');
     while ($r = $res->fetch_assoc()) {
         $accessibleIds[] = $r['id'];
     }
     $res->close();
     if (!empty($accessibleIds)) {
         $this->objectsClass = new \CB\Objects();
         $rez = $this->doRecursiveAction($action, $accessibleIds, $targetId);
     } else {
         throw new \Exception(L\get('Access_denied'), 1);
     }
     DB\commitTransaction();
     return $rez;
 }
    WHERE `sys_data` LIKE \'%"subscribers"%\'') or die(DB\dbQueryError());
if ($r = $res->fetch_assoc()) {
    echo "Total objects: " . $r['nr'] . "\n";
}
$res->close();
DB\startTransaction();
//iterate and upgrade each object
$i = 0;
$res = DB\dbQuery('SELECT id, sys_data
    FROM objects
    WHERE `sys_data` LIKE \'%"subscribers"%\'') or die(DB\dbQueryError());
while ($r = $res->fetch_assoc()) {
    if ($i > 100) {
        $i = 0;
        echo '.';
    }
    $d = Util\toJSONArray($r['sys_data']);
    if (empty($d['fu'])) {
        $d['fu'] = array();
    }
    $su = $d['subscribers']['on'];
    unset($d['subscribers']);
    $d['fu'] = array_unique(Util\toNumericArray(array_merge($d['fu'], $su)));
    DB\dbQuery('UPDATE objects
        SET `sys_data` = $2
        WHERE id = $1', array($r['id'], Util\jsonEncode($d))) or die(DB\dbQueryError());
    $i++;
}
$res->close();
DB\commitTransaction();
echo "\nDone";