Exemplo n.º 1
0
 /**
  * get a child node id by its name under specified $pid
  * @param  int           $id
  * @param  varchar|array $name direct child name or the list of child, subchild, ...
  * @return int|null
  */
 public static function getChildId($pid, $name)
 {
     if (!is_array($name)) {
         $name = array($name);
     }
     do {
         $n = array_shift($name);
         $r = DM\Tree::getChildByName($pid, $n);
         if (!empty($r)) {
             $pid = $r['id'];
         } else {
             $pid = null;
         }
     } while (!empty($pid) && !empty($name));
     return $pid;
 }
Exemplo n.º 2
0
 public function mkTreeDir($pid, $dir)
 {
     if (empty($dir) || $dir == '.') {
         return $pid;
     }
     $path = str_replace('\\', '/', $dir);
     $path = explode('/', $path);
     $userId = User::getId();
     foreach ($path as $dir) {
         if (empty($dir)) {
             continue;
         }
         $r = DM\Tree::getChildByName($pid, $dir);
         if (!empty($r)) {
             $pid = $r['id'];
         } else {
             $pid = DM\Tree::create(array('pid' => $pid, 'name' => $dir, 'type' => 1, 'cid' => $userId, 'uid' => $userId, 'template_id' => Config::get('default_folder_template')));
         }
     }
     return $pid;
 }
Exemplo n.º 3
0
 /**
  * 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";
 }