/**
  * Rename the descenedent children for which we need to rename  its paths
  * @param I2CE_MagicDataNode $node 
  * @param array $children an array of child paths we need to rename its path
  */
 protected function renameDecendents($node, $children)
 {
     $ret = true;
     foreach ($children as $old => $new) {
         //these are the old child paths
         $old_key = $this->getKey($node, $old);
         //existing key
         $values = $this->memcached->get($old_key);
         if (!is_array($values)) {
             continue;
         }
         $new_key = $this->getKey($node, $new);
         $values['path'] = $this->getChildPath($node, $new);
         if (!$this->memcached->set($new_key, $values, self::TIMEOUT)) {
             I2CE_MagicDataNode::raiseError("Error renaming {$old} to {$new} in MemCached " . $node->getPath());
             $ret = false;
             continue;
         }
         $this->memcached->delete($old_key);
         $t_children = array();
         foreach ($values['children'] as $t_child) {
             $t_children[$old . '/' . $t_child] = $new . '/' . $t_child;
         }
         $this->renameDescendents($node, $t_children);
     }
     return $ret;
 }
 /**
  * Store the given I2CE_MagicDataNode into the database.
  * @param I2CE_MagicDataNode $node
  */
 public function store($node)
 {
     if ($node instanceof I2CE_MagicData) {
         $parent = '';
         $name = '';
         $path = '/';
     } else {
         $name = $node->getName();
         if (is_string($name) && strlen($name) == 0) {
             I2CE::raiseError("Non-existent name on a non-root magic data node");
             return false;
         }
         $parentNode = $node->getParent();
         if ($parentNode instanceof I2CE_MagicData) {
             $parent = '/';
             $path = '/' . $name;
         } else {
             $parent = $parentNode->getPath(false);
             $path = $parent . '/' . $name;
         }
     }
     $value = $node->getSaveValue();
     //$path_hash = md5($path);
     $path_hash = $this->getHash($node);
     if ($this->db_statements['store']->execute(array($path_hash, $parent, $name, $node->getType(), $value))) {
         return true;
     } else {
         I2CE_MagicDataNode::raiseError("Error saving to DB " . $node->getPath() . " Type: " . $node->getType() . " Value: " . $value);
         return false;
     }
 }
 /**
  * Store the given I2CE_MagicDataNode into the database.
  * @param I2CE_MagicDataNode $node
  */
 public function store($node)
 {
     $hash = $this->getHash($node);
     $value = $node->getSaveValue();
     $children = $node->getKeys(null, true);
     if (count($children) > 0) {
         $children_str = implode(",", $children);
     } else {
         $children_str = null;
     }
     if ($this->db_statements['store']->execute(array($hash, $node->getPath(), $node->getType(), $value, $children_str))) {
         return TRUE;
     } else {
         I2CE_MagicDataNode::raiseError("Error saving to DB " . $node->getPath() . " Type: " . $node->getType() . " Value: " . $value . " Children: " . implode(',', $children));
         return FALSE;
     }
 }
Пример #4
0
 /**
  * Retrieve the given magic data node (which should be a
  * descendent of this instance.)
  *
  * @param I2CE_MagicDataNode $node
  * @return array
  */
 public function retrieve($node)
 {
     $node_data = array();
     $i_start = 0;
     if ($node->volatile()) {
         //if the node is volatile we want to retrieve if from the
         //last storage mechanism added as
         //it is considered the most secure
         $i_start = $this->num_storage - 1;
     }
     for ($i = $i_start; $i < $this->num_storage; $i++) {
         $node_data = $this->storage[$i]->retrieve($node);
         if (is_array($node_data) && count($node_data) > 0) {
             if (!(array_key_exists('type', $node_data) && array_key_exists('value', $node_data) && array_key_exists('children', $node_data))) {
                 I2CE_MagicDataNode::raiseError($node->getPath() . ": got invalid data " . print_r($node_data, true) . " from " . get_class($this->storage[$i]), E_ERROR);
                 $node_data = array();
             } else {
                 if ($node_data['type'] == I2CE_MagicDataNode::TYPE_NOT_POPULATED) {
                     I2CE_MagicDataNode::raiseError("Retreived unpopulated type at " . $node->getPath() . " from " . get_class($this->storage[$i]));
                     $node_data = array();
                 } else {
                     break;
                 }
             }
         }
     }
     return array("storage_idx" => $i, "data" => $node_data);
 }
 /**
  * Rename the descenedent children for which we need to rename  its paths
  * @param I2CE_MagicDataNode $node 
  * @param array $children an array of child paths we need to rename its path
  */
 protected function renameDecendents($node, $children)
 {
     $ret = true;
     foreach ($children as $old => $new) {
         //these are the old child paths
         $old_hash = $this->getHash($node, $old);
         //existing hash
         $fetch = apc_fetch($this->getPrefix("data") . $old_hash);
         if ($fetch === false) {
             continue;
         }
         $values = unserialize($fetch);
         if (!is_array($values)) {
             continue;
         }
         $new_hash = $this->getHash($node, $new);
         $values['path'] = $this->getChildPath($node, $new);
         if (apc_store($this->getPrefix("data") . $new_hash, serialize($values), self::APC_TIMEOUT) !== true) {
             I2CE_MagicDataNode::raiseError("Error renaming {$old} to {$new} in APC " . $node->getPath());
             $ret = false;
             continue;
         }
         apc_delete($this->getPrefix("data") . $old_hash);
         $t_children = array();
         foreach ($values['children'] as $t_child) {
             $t_children[$old . '/' . $t_child] = $new . '/' . $t_child;
         }
         $this->renameDescendents($node, $t_children);
     }
     return $ret;
 }