Ejemplo n.º 1
0
 /**
  * @dataProvider templatesProvider
  */
 public function testTemplateCRUD($td)
 {
     $obj = new \CB\Objects\Template();
     // first create object
     $td['id'] = $obj->create($td);
     $this->assertTrue($td['id'] > 0, ' Error on create Template');
     // second read created object
     $obj->load($td['id']);
     $readTd = $obj->getData();
     $vtd = $td;
     $vtd['cfg'] = Util\toJsonArray($td['cfg']);
     $this->assertArraySubset($vtd, $readTd, false, ' Error read template data ' . print_r($readTd, true));
     // third update created object
     $td['data']['visible'] = 0;
     $td['data']['order'] = 2;
     $td['data']['iconCls'] = '';
     $obj->update($td);
     $obj->load($td['id']);
     $readTd = $obj->getData();
     $vtd = $td;
     $vtd['cfg'] = Util\toJsonArray($td['cfg']);
     $this->assertArraySubset($vtd, $readTd, false, ' error on updated template data ' . print_r($readTd, true));
 }
Ejemplo n.º 2
0
 /**
  * update tree nodes into solr
  *
  * @param string[] $p {
  *     @type boolean $all if true then all nodes will be updated into solr,
  *                          otherwise - only the nodes marked as updated will be reindexed in solr
  *     @type int[]  $id    id or array of object ids to update
  *
  *     @type varchar $cron_id when this function is called by a cron then cron_id should be passed
  *
  *     @type boolean $nolimit if true then no limit will be applied to maximum indexed nodes
  *                            (default 2000)
  * }
  */
 public function updateTree($p = array())
 {
     /* connect to solr service */
     $this->connect();
     $eventParams = array('class' => &$this, 'params' => &$p);
     $this->folderTemplates = \CB\Config::get('folder_templates');
     \CB\fireEvent('onBeforeSolrUpdate', $eventParams);
     /** @type int the last processed document id */
     $lastId = 0;
     $indexedDocsCount = 0;
     $all = !empty($p['all']);
     $nolimit = !empty($p['nolimit']);
     /* prepeare where condition for sql depending on incomming params */
     $where = '(t.updated > 0) AND (t.draft = 0) AND (t.id > $1)';
     if ($all) {
         $this->deleteByQuery('*:*');
         $where = '(t.id > $1) AND (t.draft = 0) ';
         \CB\Templates\SingletonCollection::getInstance()->loadAll();
     } elseif (!empty($p['id'])) {
         $ids = \CB\Util\toNumericArray($p['id']);
         $where = '(t.id in (0' . implode(',', $ids) . ') ) and (t.id > $1)';
     }
     $sql = 'SELECT t.id
             ,t.pid
             ,ti.pids
             ,ti.case_id
             ,ti.acl_count
             ,ti.security_set_id
             ,t.name
             ,t.system
             ,t.template_id
             ,t.target_id
             ,t.size
             ,DATE_FORMAT(t.`date`, \'%Y-%m-%dT%H:%i:%sZ\') `date`
             ,DATE_FORMAT(t.`date_end`, \'%Y-%m-%dT%H:%i:%sZ\') `date_end`
             ,t.oid
             ,t.cid
             ,DATE_FORMAT(t.cdate, \'%Y-%m-%dT%H:%i:%sZ\') `cdate`
             ,t.uid
             ,DATE_FORMAT(t.udate, \'%Y-%m-%dT%H:%i:%sZ\') `udate`
             ,t.did
             ,DATE_FORMAT(t.ddate, \'%Y-%m-%dT%H:%i:%sZ\') `ddate`
             ,t.dstatus
             ,t.updated
             ,o.sys_data
         FROM tree t
         LEFT JOIN tree_info ti ON t.id = ti.id
         LEFT JOIN objects o ON o.id = t.id
         where ' . $where . '
         ORDER BY t.id
         LIMIT 500';
     $docs = true;
     while (!empty($docs) && ($nolimit || $indexedDocsCount < 2000)) {
         $docs = array();
         $res = DB\dbQuery($sql, $lastId) or die(DB\dbQueryError());
         while ($r = $res->fetch_assoc()) {
             $lastId = $r['id'];
             /* process full object update only if:
                    - updated = 1
                    - specific ids are specified
                    - if $all parameter is true
                */
             if ($all || !empty($p['id']) || $r['updated'] & 1) {
                 $r['sys_data'] = Util\toJsonArray($r['sys_data']);
                 $this->prepareDBRecord($r);
                 $docs[$r['id']] = $r;
             }
             $this->updateCronLastActionTime(@$p['cron_id']);
         }
         $res->close();
         if (!empty($docs)) {
             //append file contents for files to content field
             $this->appendFileContents($docs);
             $this->addDocuments($docs);
             /* reset updated flag into database for processed documents */
             DB\dbQuery('UPDATE tree
                     ,tree_info
                 SET tree.updated = 0
                     ,tree_info.updated = 0
                 WHERE tree.id in (' . implode(',', array_keys($docs)) . ')
                     AND tree_info.id = tree.id') or die(DB\dbQueryError());
             $this->updateCronLastActionTime(@$p['cron_id']);
             $this->commit();
             $indexedDocsCount += sizeof($docs);
         }
     }
     $this->updateTreeInfo($p);
     \CB\fireEvent('onSolrUpdate', $eventParams);
 }