public function updatePath($xmlDoc, $parentId, $path)
 {
     $this->loadXML($xmlDoc);
     // Build the local item tree
     $localTree = $this->getTreeFromItemElement($this->findPath($path));
     // Build the remote item tree
     try {
         // If the parentId is not defined, take the root folder
         if ($parentId === null) {
             $parentId = $this->soap->getRootFolder($this->hash, $this->groupId);
         }
         $remoteItems = $this->soap->getDocmanTreeInfo($this->hash, $this->groupId, $parentId);
         foreach ($remoteItems as $item) {
             $this->remoteItems[$item->id] = $item;
         }
         $idtree = array_pop($this->buildDistantTreeFromSoapArray());
         $remoteTree = $this->getTitleTreeFromIdTree($idtree);
     } catch (SoapFault $e) {
         $this->printSoapResponseAndThrow($e);
     }
     // Merge the trees, and tag the nodes
     $mergedTree = array_pop(Trees::mergeTag($remoteTree, $localTree));
     $tagCounts = $this->tagCount($mergedTree);
     if (!$this->continue) {
         $this->log(PHP_EOL . $tagCounts['IN_BOTH'] . " item(s) will be updated" . PHP_EOL);
     }
     $this->log($tagCounts['IN_SECOND'] . " item(s) will be created" . PHP_EOL);
     if (!$this->continue) {
         $this->log($tagCounts['IN_FIRST'] . " item(s) will be removed" . PHP_EOL);
     }
     if (!$this->continue) {
         $this->log("Are you sure you want to update the document tree? (y/n) [n] ");
     } else {
         $this->log("Are you sure you want to continue the upload? (y/n) [n] ");
     }
     $answer = strtoupper(trim(fgets(STDIN)));
     if ($answer == 'Y') {
         foreach ($this->sortChildrenArray($mergedTree['children']) as $childTitle => $subTree) {
             $this->recurseUpdateTree($childTitle, $subTree, $parentId);
         }
     }
 }
Example #2
0
 public function testMergeTag()
 {
     $tree1 = array(0 => null);
     $res = Trees::mergeTag($tree1, $tree1);
     $this->assertEqual(array('(root)' => null), $res);
     $tree1 = array(0 => null);
     $tree2 = array(1 => null);
     $res = Trees::mergeTag($tree1, $tree2);
     $this->assertEqual(array('(root)' => null), $res);
     //     0
     //    / \
     //   1   2
     //  /   / \
     // 3   4   5
     $tree1 = array(0 => array('children' => array(1 => array('children' => array(3 => null)), 2 => array('children' => array(4 => null, 5 => null)))));
     $expected = array('(root)' => array('children' => array(1 => array('children' => array(3 => array('tag' => 'IN_BOTH')), 'tag' => 'IN_BOTH'), 2 => array('children' => array(4 => array('tag' => 'IN_BOTH'), 5 => array('tag' => 'IN_BOTH')), 'tag' => 'IN_BOTH'))));
     $res = Trees::mergeTag($tree1, $tree1);
     $this->assertEqual($expected, $res);
     // Tree 1
     //
     //     0
     //    / \
     //   1   2
     //  / \   \
     // 3   4   5
     $tree1 = array(0 => array('children' => array(1 => array('children' => array(3 => null, 4 => null)), 2 => array('children' => array(5 => null))), 'somedata' => 1));
     // Tree 2
     //
     //      0
     //    / | \
     //   1  2  7
     //      |
     //      6
     $tree2 = array(0 => array('children' => array(1 => null, 2 => array('children' => array(6 => null)), 7 => array('somedata' => 2))));
     // Expected result: the two previous trees merged
     //
     //      0
     //    / | \
     //   1  7  2
     //  / \   / \
     // 3   4 5   6
     $expected = array('(root)' => array('children' => array(1 => array('children' => array(3 => array('tag' => 'IN_FIRST'), 4 => array('tag' => 'IN_FIRST')), 'tag' => 'IN_BOTH'), 2 => array('children' => array(5 => array('tag' => 'IN_FIRST'), 6 => array('tag' => 'IN_SECOND')), 'tag' => 'IN_BOTH'), 7 => array('tag' => 'IN_SECOND', 'somedata' => 2)), 'somedata' => 1));
     $res = Trees::mergeTag($tree1, $tree2);
     $this->assertEqual($expected, $res);
 }