public function testRecordCreate() { $name = 'aTestGUIDName'; $id = DM\GUID::toId($name); if (is_numeric($id)) { DM\GUID::delete($id); } $id = DM\GUID::toId($name); $this->assertTrue(!is_numeric($id), 'toId: returned an id for non existent name'); $rez = DM\GUID::readNames(array($name)); $this->assertTrue(empty($rez[$name]), 'readNames: returned id for non existent name'); // now create record and check the same $id = DM\GUID::create(array('name' => $name)); $this->assertTrue(is_numeric($id), 'Cant create a guid'); $id = DM\GUID::toId($name); $this->assertTrue(is_numeric($id), 'toId: cant get id for created guid name'); $rez = DM\GUID::readNames(array($name)); $this->assertTrue(!empty($rez[$name]), 'readNames: doesnt return id for our name'); }
/** * get GUIDs virtual tree node names array * @param array $names * @return int */ public static function getGUIDs($names) { $rez = array(); $guids = Cache::get('GUIDS', array()); if (!empty($guids)) { foreach ($names as $name) { if (!empty($guids[$name])) { $rez[$name] = $guids[$name]; } } //remove names retreived from cache $names = array_diff($names, array_keys($rez)); } //get remained names from db if (!empty($names)) { $dbNames = DM\GUID::readNames($names); $guids = array_merge($guids, $dbNames); $rez = array_merge($rez, $dbNames); //remove names retreived from db $names = array_diff($names, array_keys($rez)); } //create guids for remained names foreach ($names as $name) { $rez[$name] = DM\GUID::create(array('name' => $name)); $guids[$name] = $rez[$name]; } //update cache variable Cache::set('GUIDS', $guids); return $rez; }