/** * @group ezurl */ public function testFetchByUrl() { $url = 'http://ez.no/ezpublish'; $urlObj = eZURL::create($url); $urlObj->store(); $urlObj2 = eZURL::fetchByUrl($url); self::assertInstanceOf('eZURL', $urlObj2); }
static function registerURLArray( $urlArray ) { $db = eZDB::instance(); foreach( $urlArray as $key => $url ) { $urlArrayTmp[$key] = $db->escapeString( $url ); } // Fetch the already existing URL's $inURLSQL = implode( '\', \'', $urlArrayTmp ); $checkURLQuery = "SELECT id, url FROM ezurl WHERE url IN ( '$inURLSQL' )"; $urlRowArray = $db->arrayQuery( $checkURLQuery ); $registeredURLArray = array(); foreach ( $urlRowArray as $urlRow ) { $registeredURLArray[$urlRow['url']] = $urlRow['id']; } // Check for URL's which are not registered, and register them foreach ( $urlArray as $url ) { if ( !isset( $registeredURLArray[$url] ) ) { $url = eZURL::create( $url ); $url->store(); $urlID = $url->attribute( 'id' ); $urlText = $url->attribute('url' ); $registeredURLArray[$urlText] = $urlID; } } return $registeredURLArray; }
function unserializeContentObjectAttribute($package, $objectAttribute, $attributeNode) { /* For all links found in the XML, do the following: * Search for url specified in 'href' link attribute (in ezurl table). * If the url not found then create a new one. * Then associate the found (or created) URL with the object attribute by creating new url-object link. * After that, remove "href" attribute, add new "id" attribute. * This new 'id' will always refer to the existing url object. */ $linkNodes = $attributeNode->getElementsByTagName('link'); foreach ($linkNodes as $linkNode) { $href = $linkNode->getAttribute('href'); if (!$href) { continue; } $urlObj = eZURL::urlByURL($href); if (!$urlObj) { $urlObj = eZURL::create($href); $urlObj->store(); } $linkNode->removeAttribute('href'); $linkNode->setAttribute('url_id', $urlObj->attribute('id')); $urlObjectLink = eZURLObjectLink::create($urlObj->attribute('id'), $objectAttribute->attribute('id'), $objectAttribute->attribute('version')); $urlObjectLink->store(); } foreach ($attributeNode->childNodes as $childNode) { if ($childNode->nodeType == XML_ELEMENT_NODE) { $xmlString = $childNode->ownerDocument->saveXML($childNode); $objectAttribute->setAttribute('data_text', $xmlString); break; } } }