$script->shutdown(1); } // Clean up all tables to add everything from the start. eZISBNGroup::cleanAll(); eZISBNGroupRange::cleanAll(); eZISBNRegistrantRange::cleanAll(); // Get registration groups. $registrationGroups = $xml->xpath('RegistrationGroups/Group'); foreach ($registrationGroups as $group) { // Prefix is always 978 or 979 followed by an hyphen (-) and up to 5 digits // Explode it in order to get the group number $prefixArray = explode('-', $group->Prefix); $groupNumber = $prefixArray[1]; $description = $group->Agency; // name $isbnGroup = eZISBNGroup::create($groupNumber, $description); $isbnGroup->store(); $isbnGroupID = $isbnGroup->attribute('id'); // look for the rules $rules = $group->Rules[0]->Rule; foreach ($rules as $rule) { $length = (int) $rule->Length; // if length is 0 there is no need to add to the database if ($length > 0) { $rangeArray = explode('-', $rule->Range); $fromValue = substr($rangeArray[0], 0, 5); $toValue = substr($rangeArray[1], 0, 5); $registrantFrom = substr($rangeArray[0], 0, $length); $registrantTo = substr($rangeArray[1], 0, $length); $registrationGroup = eZISBNRegistrantRange::create($isbnGroupID, $fromValue, $toValue, $registrantFrom, $registrantTo, $length); $registrationGroup->store();
$added = true; } if ($isbnRegGroupElementTo + 1 == $fromTestValue) { $registrationGroupArray[$length][$i]['from'] = $isbnRegGroupElementFrom; $added = true; } } // Since the range is not found as a continued range from the other ranges, so // create a new one. if ($added == false) { $registrationGroupArray[$length][] = array('from' => $isbnRegGroupElementFrom, 'to' => $isbnRegGroupElementTo); } } else { $registrationGroupArray[$length][] = array('from' => $isbnRegGroupElementFrom, 'to' => $isbnRegGroupElementTo); } $isbnGroup = eZISBNGroup::create($isbnRegGroupElement, $isbnItem['text']); $isbnGroup->store(); $isbnGroupID = $isbnGroup->attribute('id'); $pubRangeArray = $isbnItem['pubrange']; if (is_array($pubRangeArray)) { foreach ($pubRangeArray as $isbnRegistrantRange) { // The test number should have a base with 5 digits where from should be padded with 0 and // to should be padded with 9. $fromValue = (int) substr(str_pad($isbnRegistrantRange['from'], 5, 0, STR_PAD_RIGHT), 0, 5); $toValue = (int) substr(str_pad($isbnRegistrantRange['to'], 5, 9, STR_PAD_RIGHT), 0, 5); $length = $isbnRegistrantRange['length']; $registrationGroup = eZISBNRegistrantRange::create($isbnGroupID, $fromValue, $toValue, $isbnRegistrantRange['from'], $isbnRegistrantRange['to'], $length); $registrationGroup->store(); } } }