/** * get data model pid that is different from tree one * @param int $pid * @return int */ protected function getDMPid($pid) { $rez = null; $name = Objects::getName($pid); $id = DM\Config::toId($name, 'param'); if (is_numeric($id)) { $rez = $id; } return $rez; }
protected function moveCustomDataTo($targetId) { DM\Config::update(array('id' => $this->id, 'pid' => $targetId)); }
/** * sync config table ids with those from tree * @return void */ protected function syncConfigIds() { echo "Sync config ids .. "; $rootId = Browser::getRootFolderId(); $pid = Objects::getChildId($rootId, 'System'); $pid = Objects::getChildId($pid, 'Config'); $ref = array(); $left = array(); $lastLength = 0; $rows = DM\Config::readAll(); //add root nodes foreach ($rows as &$r) { if (empty($r['pid'])) { $tr = DM\Tree::getChildByName($pid, $r['param']); if (empty($tr)) { DM\Config::delete($r['id']); } else { $ref[$r['id']] =& $r; $r['treeRecord'] = $tr; } } else { $left[] =& $r; } } while (!empty($left) && sizeof($left) != $lastLength) { $rows = $left; $lastLength = sizeOf($left); $left = array(); foreach ($rows as &$r) { if (isset($ref[$r['pid']]) && !empty($ref[$r['pid']]['treeRecord'])) { $ref[$r['id']] =& $r; $r['treeRecord'] = DM\Tree::getChildByName($ref[$r['pid']]['treeRecord']['id'], $r['param']); } else { $left[] =& $r; } } } //iterate and update config table foreach ($ref as &$r) { $tr = $r['treeRecord']; $pid = empty($ref[$r['pid']]['treeRecord']) ? null : $ref[$r['pid']]['treeRecord']['id']; DB\dbQuery('UPDATE config SET id = $2 ,pid = $3 WHERE id = $1', array($r['id'], $tr['id'], $pid)); } echo "Ok \n"; }
/** * get core config stored in database * * TODO: remove this method after config migration * @return array */ private static function getCoreDBConfig() { $rez = array(); $ref = array(); $left = array(); $lastLength = 0; $rows = DM\Config::readAll(); //add root nodes foreach ($rows as &$r) { if (empty($r['pid'])) { $ref[$r['id']] =& $r; } else { $left[] =& $r; } } while (!empty($left) && sizeof($left) != $lastLength) { $rows = $left; $lastLength = sizeOf($left); $left = array(); foreach ($rows as &$r) { if (isset($ref[$r['pid']])) { $p =& $ref[$r['pid']]; if (!is_array($p['value'])) { $p['value'] = Util\toJSONArray($p['value']); } $r['value'] = Util\toJSONArray($r['value']); $p['value'][$r['param']] =& $r['value']; $ref[$r['id']] =& $r; } else { $left[] =& $r; } } } //iterate and collect resulting items foreach ($ref as &$r) { if (empty($r['pid'])) { $rez[$r['param']] = $r['value']; } } return $rez; }
/** * transfer config options to tree * @return void */ protected function syncConfigToTree() { $o = new \CB\Objects\Object(); $co = new \CB\Objects\Config(); $recs = DM\Config::readAll(); foreach ($recs as $r) { //detect option type $type = ''; switch ($r['param']) { case 'default_event_template': case 'default_file_template': case 'default_folder_template': case 'default_task_template': $type = 'int'; break; case 'default_language': case 'languages': case 'project_name_en': case 'project_name_ru': $type = 'varchar'; break; case 'folder_templates': case 'max_files_version_count': case 'templateIcons': $type = 'text'; break; case 'facet_configs': case 'js': case 'maintenance_cfg': case 'node_facets': case 'rootNode': case 'object_type_plugins': case 'treeNodes': $type = 'json'; break; case 'responsible_party': case 'responsible_party_default': case 'task_categories': case 'maintenance_mode': continue; default: if (is_numeric($r['value'])) { $type = 'int'; } else { $type = 'text'; } } if (empty($type)) { continue; } $childs = array(); if ($r['param'] == 'folder_templates') { $r['value'] .= ',' . $this->templateIds["Config json option"]; DM\Config::update($r); } if ($r['param'] == 'treeNodes') { $childs = Util\toJSONArray($r['value']); $r['value'] = ''; DM\Config::update($r); } $pid = $o->create(array('id' => null, 'pid' => $this->cfg['configFolderId'], 'template_id' => $this->templateIds["Config {$type} option"], 'name' => $r['param'], 'data' => array('_title' => $r['param'], 'value' => $r['value']))); $i = 1; foreach ($childs as $k => $v) { $co->create(array('id' => null, 'pid' => $pid, 'template_id' => $this->templateIds["Config {$type} option"], 'name' => $k, 'data' => array('_title' => $k, 'value' => json_encode($v, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT), 'order' => $i++))); } } //add menu rule for Menus folder $pid = Objects::getChildId($this->systemFolderId, 'Menus'); $tempalteIds = DM\Templates::getIdsByType('menu'); $o->create(array('id' => null, 'pid' => $pid, 'template_id' => $tempalteIds[0], 'name' => 'Create config options rule', 'data' => array('_title' => 'Create config options rule', 'node_ids' => $this->cfg['configFolderId'], 'menu' => $this->templateIds['Config int option'] . ',' . $this->templateIds['Config varchar option'] . ',' . $this->templateIds['Config text option'] . ',' . $this->templateIds['Config json option']))); }
showMessage(); } $cbDb = $cfg['prefix'] . '__casebox'; echo 'Registering core .. '; \CB\DB\dbQuery('REPLACE INTO ' . $cbDb . ' .cores (name, cfg) VALUES ($1, $2)', array($coreName, '{}')); showMessage(); //ask to provide root email & password $email = ''; $pass = ''; do { $email = readParam('core_root_email'); } while (\CB\Cache::get('RUN_SETUP_INTERACTIVE_MODE') && empty($email)); do { $pass = readParam('core_root_pass'); } while (\CB\Cache::get('RUN_SETUP_INTERACTIVE_MODE') && empty($pass)); DB\dbQuery("use `{$dbName}`"); if (!empty($email) || !empty($pass)) { DM\Users::updateByName(array('name' => 'root', 'password' => $pass, 'email' => $email, 'data' => '{"email": "' . $email . '"}')); } //set core languages $sql = 'REPLACE INTO `config` (id, param, `value`) VALUES ($1, $2, $3);'; $language = readParam('core_default_language', 'en'); DB\dbQuery($sql, array(DM\Config::toId('default_language', 'param'), 'default_language', $language)); $languages = readParam('core_languages', $language); DB\dbQuery($sql, array(DM\Config::toId('languages', 'param'), 'languages', $languages)); createSolrCore($cfg, $coreName); echo 'Creating language files .. '; exec('php "' . $binDirectorty . 'languages_update_js_files.php"'); showMessage(); echo "Done.\n";
/** * get core config stored in database * * TODO: remove this method after config migration * @return array */ private static function getCoreDBConfig() { $rez = array(); $ref = array(); $rows = DM\Config::readAll(); foreach ($rows as $r) { $ref[$r['id']] = $r['param']; if (empty($r['pid'])) { $rez[$r['param']] = $r['value']; } else { $parent =& $rez[$ref[$r['pid']]]; if (!is_array($parent)) { $rez[$ref[$r['pid']]] = Util\toJSONArray($parent); } $rez[$ref[$r['pid']]][$r['param']] = Util\toJSONArray($r['value']); } } return $rez; }