/** * description * * @return int * * @param integer $v Schema Id to lookup */ public static function getNextSchemaPropertyId($v) { //lookup the schema $schema = SchemaPeer::retrieveByPK($v); $nextId = NULL; if ($schema) { //get the last id $lastId = $schema->getLastUriId(); //increment it by one and set the last_id $nextId = $lastId ? ++$lastId : 100000; //we should theoretically set this when we save the property, but it doesn't matter $schema->setLastUriId($nextId); $schema->save(); return $nextId; } }
function it_finds_an_array_of_all_columns_based_on_a_schema_id_in_display_order() { $schema = \SchemaPeer::retrieveByPK(1); $schema->setLanguages(['en','fr']); $schema->save(); /** @var \ImportVocab\ExportVocab $this */ $this->setAsTemplate(true); $columns = $this->getSchema()->getAllProfileProperties(); $columns->shouldHaveCount( 26 ); $columns[1]['profile']->shouldHaveType( 'ProfileProperty' ); $columns[9]['count']->shouldEqual( 1 ); $columns[3]['languages']['en']->shouldEqual( 1 ); $columns[3]['languages']['fr']->shouldEqual( 1 ); $id = \ProfilePropertyPeer::retrieveByPK( 9 )->getId(); $columns[12]['id']->shouldEqual( $id ); }
$history = $import->getConceptPropertyHistorys(); $showVocabularyBc = true; $showHistoryBc = true; $tab = 'vocabulary'; } } } break; case 'schemahistorylist': $showBc = true; $showSchemaBc = true; if ('import' == $filter) { $import = FileImportHistoryPeer::retrieveByPK($paramId); if ($import) { $id = $import->getSchemaId(); $schema = SchemaPeer::retrieveByPK($id); } } if (!isset($history)) { $id = $sf_params->get('id'); if ($id) { $history = SchemaPropertyElementHistoryPeer::retrieveByPK($id); } } if (!isset($schema_property_element)) { if ($history) { sfPropelParanoidBehavior::disable(); $schema_property_element = $history->getSchemaPropertyElement(); } } if (!isset($schema_property)) {
function run_import_marc_vocabulary($task, $args) { //check the argument counts if (count($args) < 1) { throw new Exception('You must provide a vocabulary type.'); } if (count($args) < 2) { throw new Exception('You must provide a file name.'); } if (count($args) < 3) { throw new Exception('You must provide a vocabulary id.'); } //set the arguments $type = strtolower($args[0]); $filePath = $args[1]; $id = $args[2]; $deleteMissing = (isset($args[3]) && ("-d" == $args[3])); //do some basic validity checks if (! in_array($type, array("schema", "vocab", "vocabulary"))) { throw new Exception('You must import into a schema or a vocab'); } if ("vocabulary" == $type) { $type = "vocab"; } if (! is_numeric($id)) { throw new Exception('You must provide a valid ID'); } //does the file exist? if (! file_exists($filePath)) { throw new Exception('You must supply a valid file to import: ' . $filePath); } //is the file a valid type? if (preg_match('/^.+\.([[:alpha:]]{2,4})$/', $filePath, $matches)) { if (! in_array(strtolower($matches[1]), array("json", "rdf", "csv", "xml"))) { throw new Exception('You must provide a valid file type based on the extension'); } } else { throw new Exception("File type cannot be determined from the file extension"); } $fileType = $matches[1]; //is the object a valid object? if ('vocab' == $type) { $vocabObj = VocabularyPeer::retrieveByPK($id); if (is_null($vocabObj)) { throw new Exception('Invalid vocabulary ID'); } //set some defaults $baseDomain = $vocabObj->getBaseDomain(); $language = $vocabObj->getLanguage(); $statusId = $vocabObj->getStatusId(); //get a skos property id map $skosMap = SkosPropertyPeer::getPropertyNames(); //there has to be a hash or a slash $tSlash = preg_match('@(/$)@i', $vocabObj->getUri()) ? '' : '/'; $tSlash = preg_match('/#$/', $vocabObj->getUri()) ? '' : $tSlash; } else { $schemaObj = SchemaPeer::retrieveByPK($id); if (is_null($schemaObj)) { throw new Exception('Invalid schema ID'); } //set some defaults $baseDomain = $schemaObj->getUri(); $language = $schemaObj->getLanguage(); $statusId = $schemaObj->getStatusId(); //get a element set property id map $profileId = 1; $profile = ProfilePeer::retrieveByPK($profileId); $elementMap = $profile->getAllProperties(); //there has to be a hash or a slash $tSlash = preg_match('@(/$)@i', $baseDomain) ? '' : '/'; $tSlash = preg_match('/#$/', $baseDomain) ? '' : $tSlash; } // insert jon's user id $userId = 36; /* From here on the process is the same regardless of UI */ //execute // parse file to get the fields/columns and data $file = fopen($filePath, "r"); if (! $file) { throw new Exception("Can't read supplied file"); } // check to see if file has been uploaded before // check import history for file name $importHistory = FileImportHistoryPeer::retrieveByLastFilePath($filePath); // if reimport // get last import history for filename // unserialize column map // match column names to AP based on map // look for matches in unmatched field/column names to AP (ideal) // csv table of data -- // row1: parsed field names/column headers // row2: select dropdown with available fields from object AP (pre-select known matches) // each select identified by column number // row3: display datatype of selected field (updated dynamically when field selected) // row4-13: first 10 rows of parsed data from file // require a column that can match to 'URI' (maybe we'll allow an algorithm later) // require columns that are required by AP // on reimport there should be a flag to 'delete missing properties' from the current data // note: at some point there will be a reimport process that allows URI changing // this will require that there be an OMR identifier embedded in the incoming data switch ($fileType) { case "csv": try { $reader = new aCsvReader($filePath); } catch(Exception $e) { throw new Exception("Not a happy CSV file!"); } if ('vocab' == $type) { // Get array of heading names found $headings = $reader->getHeadings(); $fields = ConceptPeer::getFieldNames(); //set the map // $map[] = array("property" => "Uri", "column" => "URILocal"); // $map[] = array("property" => "prefLabel", "column" => "skos:prefLabel"); // $map[] = array("property" => "definition", "column" => "skos:definition"); // $map[] = array("property" => "notation", "column" => "skos:notation"); // $map[] = array("property" => "scopeNote", "column" => "skos:scopeNote"); $map = array( "uri" => "URILocal", "prefLabel" => "skos:prefLabel", "definition" => "skos:definition", "notation" => "skos:notation", "scopeNote" => "skos:scopeNote" ); $rows = 0; //executeImport: // serialize the column map try { while ($row = $reader->getRow()) { $rows ++; // lookup the URI (or the OMR ID if available) for a match $uri = $baseDomain . $row[$map["uri"]]; $concept = ConceptPeer::getConceptByUri($uri); $updateTime = time(); $language = (isset($map['language'])) ? $row[$map['language']] : $vocabObj->getLanguage(); if (! $concept) { // create a new concept or element $concept = new Concept(); $concept->setVocabulary($vocabObj); $concept->setUri($uri); /** * @todo Need to handle updates for topconcept here, just like language **/ $concept->setIsTopConcept(false); $concept->updateFromRequest( $userId, fixMarcEncoding(rtrim($row[$map['prefLabel']])), $language, $statusId ); } //don't update the concept if the preflabel matches else if ($row[$map['prefLabel']] != $concept->getPrefLabel()) { $concept->updateFromRequest($userId, fixMarcEncoding(rtrim($row[$map['prefLabel']]))); } //there needs to be a language to lookup the properties unless it's an objectProperty $rowLanguage = (isset($map['language'])) ? $row[$map['language']] : $concept->getLanguage(); foreach ($map as $key => $value) { //we skip because we already did them if (! in_array($key, array('uri', 'prefLabel', 'language'))) { $skosId = $skosMap[$key]; //check to see if the property already exists $property = ConceptPropertyPeer::lookupProperty($concept->getId(), $skosId, $rowLanguage); //create a new property for each unmatched column if (! empty($row[$value])) { if (! $property) { $property = new ConceptProperty(); $property->setCreatedUserId($userId); $property->setConceptId($concept->getId()); $property->setCreatedAt($updateTime); $property->setSkosPropertyId($skosId); } if (($row[$value] != $property->getObject()) || ($rowLanguage != $property->getLanguage()) ) { /** * @todo We need a check here for skos objectproperties and handle differently **/ if ($rowLanguage != $property->getLanguage()) { $property->setLanguage($rowLanguage); } if ($row[$value] != $property->getObject()) { $property->setObject(fixMarcEncoding(rtrim($row[$value]))); } $property->setUpdatedUserId($userId); $property->setUpdatedAt($updateTime); $property->save(); } } //the row value is empty else if ($deleteMissing && $property) { $property->delete(); } } } // else // lookup and update concept or element // lookup and update each property // update the history for each property, action is 'import', should be a single timestamp for all (this should be automatic) // if 'delete missing properties' is true // delete each existing, non-required property that wasn't updated by the import } } catch(Exception $e) { // catch // if there's an error of any kind, write to error log and continue echo "Error on row: " . $rows . ", " . $uri . "\n" . $e . "\n"; continue; } $objects = $vocabObj->countConcepts(); } else //it's an element set { $map = array( "uri" => "uriLocalPart", "name" => "reg:name", "definition" => "skos:definition", "label" => "rdfs:label", "note" => array("tag" => "tagCap", "ind1" => "ind1Cap", "ind2" => "ind2Cap", "sub" => "subCap") ); $rows = 0; //executeImport: // serialize the column map try { while ($row = $reader->getRow()) { // lookup the URI (or the OMR ID if available) for a match //There always has to be a URI on either update or create if (! isset($row[$map["uri"]])) { throw new Exception('Missing URI for row: ' . $reader->getRowCount()); continue; } $rows ++; $uri = $baseDomain . $tSlash . $row[$map["uri"]]; $property = SchemaPropertyPeer::retrieveByUri($uri); $updateTime = time(); $rowLanguage = (isset($map['language'])) ? $row[$map['language']] : $language; $rowStatusId = (isset($map['status'])) ? $row[$map['status']] : $statusId; if (! $property) { // create a new property /** @var SchemaProperty * */ $property = new SchemaProperty(); $property->setSchema($schemaObj); $property->setUri($uri); $property->setCreatedUserId($userId); $property->setCreatedAt($updateTime); } $property->setLanguage($rowLanguage); $property->setStatusId($rowStatusId); $property->setUpdatedUserId($userId); $property->setUpdatedAt($updateTime); if (isset($row[$map["label"]])) { $property->setLabel($row[$map["label"]]); } if (isset($row[$map["name"]])) { $property->setName($row[$map["name"]]); } if (isset($row[$map["definition"]])) { $property->setDefinition($row[$map["definition"]]); } if (is_array($map["note"])) { $note = ''; foreach ($map["note"] as $key => $value) { $caption = ! empty($row[$value]) ? " (" . $row[$value] . ")" : ' (no caption)'; $note .= ! empty($row[$key]) ? $key . ": " . $row[$key] . $caption . "<br />" : ""; } $property->setNote($note); } else { if (isset($row[$map["note"]])) { $property->setNote($row[$map["note"]]); } } $property->saveSchemaProperty($userId); /** * @todo Need to handle domain and range **/ foreach ($map as $key => $value) { //we skip because we already did them if (! in_array( $key, array('uri', 'status', 'language', 'label', 'name', 'definition', 'comment', 'note') ) ) { $elementId = $elementMap[$key]; //check to see if the property already exists //note that this also checks the object value as well, so there's no way to update or delete an existing triple //the sheet would have to conatin the identifier for the triple $element = SchemaPropertyElementPeer::lookupElement( $schemaObj->getId(), $elementId, $map[$value] ); //create a new property for each unmatched column if (! empty($row[$value])) { if (! $element) { $element = new SchemaPropertyElement(); $element->setCreatedUserId($userId); $element->setCreatedAt($updateTime); $element->setProfilePropertyId($elementId); } if (($row[$value] != $element->getObject()) || ($rowLanguage != $element->getLanguage()) ) { /** * @todo We need a check here for objectproperties and handle differently **/ if ($rowLanguage != $element->getLanguage()) { $element->setLanguage($rowLanguage); } if ($row[$value] != $element->getObject()) { $element->setObject($row[$value]); } $element->setUpdatedUserId($userId); $element->setUpdatedAt($updateTime); $element->save(); } } //the row value is empty else if ($deleteMissing && $element) { $element->delete(); } } } // else // lookup and update concept or element // lookup and update each property // update the history for each property, action is 'import', should be a single timestamp for all (this should be automatic) // if 'delete missing properties' is true // delete each existing, non-required property that wasn't updated by the import } } catch(Exception $e) { // catch // if there's an error of any kind, write to error log and continue echo "Error on row: " . $rows . ", " . $uri . "\n" . $e . "\n"; continue; } $objects = $schemaObj->countSchemaPropertys(); } // save the import history file (match timestamp to history entries) break; case "json": break; case "rdf": break; case "xml": break; default: } /* output to stdout*/ // number of objects imported (link to history, filtered on timestamp of import) echo "File:" . $filePath . ";\n Objects imported: " . $objects . "; Rows read: " . $rows . "\n"; // number of errors (link to error log) }
/** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this Agent is new, it will return * an empty collection; or if this Agent has previously * been saved, it will retrieve related Schemas from storage. * * This method is protected by default in order to keep the public * api reasonable. You can provide public methods for those you * actually need in Agent. */ public function getSchemasJoinProfile($criteria = null, $con = null) { // include the Peer class include_once 'lib/model/om/BaseSchemaPeer.php'; if ($criteria === null) { $criteria = new Criteria(); } elseif ($criteria instanceof Criteria) { $criteria = clone $criteria; } if ($this->collSchemas === null) { if ($this->isNew()) { $this->collSchemas = array(); } else { $criteria->add(SchemaPeer::AGENT_ID, $this->getId()); $this->collSchemas = SchemaPeer::doSelectJoinProfile($criteria, $con); } } else { // the following code is to determine if a new query is // called for. If the criteria is the same as the last // one, just return the collection. $criteria->add(SchemaPeer::AGENT_ID, $this->getId()); if (!isset($this->lastSchemaCriteria) || !$this->lastSchemaCriteria->equals($criteria)) { $this->collSchemas = SchemaPeer::doSelectJoinProfile($criteria, $con); } } $this->lastSchemaCriteria = $criteria; return $this->collSchemas; }
/** * Selects a collection of FileImportHistory objects pre-filled with all related objects except Batch. * * @return array Array of FileImportHistory objects. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doSelectJoinAllExceptBatch(Criteria $c, $con = null) { $c = clone $c; // Set the correct dbName if it has not been overridden // $c->getDbName() will return the same object if not set to another value // so == check is okay and faster if ($c->getDbName() == Propel::getDefaultDB()) { $c->setDbName(self::DATABASE_NAME); } FileImportHistoryPeer::addSelectColumns($c); $startcol2 = FileImportHistoryPeer::NUM_COLUMNS - FileImportHistoryPeer::NUM_LAZY_LOAD_COLUMNS + 1; UserPeer::addSelectColumns($c); $startcol3 = $startcol2 + UserPeer::NUM_COLUMNS; VocabularyPeer::addSelectColumns($c); $startcol4 = $startcol3 + VocabularyPeer::NUM_COLUMNS; SchemaPeer::addSelectColumns($c); $startcol5 = $startcol4 + SchemaPeer::NUM_COLUMNS; $c->addJoin(FileImportHistoryPeer::USER_ID, UserPeer::ID); $c->addJoin(FileImportHistoryPeer::VOCABULARY_ID, VocabularyPeer::ID); $c->addJoin(FileImportHistoryPeer::SCHEMA_ID, SchemaPeer::ID); $rs = BasePeer::doSelect($c, $con); $results = array(); while ($rs->next()) { $omClass = FileImportHistoryPeer::getOMClass(); $cls = Propel::import($omClass); $obj1 = new $cls(); $obj1->hydrate($rs); $omClass = UserPeer::getOMClass(); $cls = Propel::import($omClass); $obj2 = new $cls(); $obj2->hydrate($rs, $startcol2); $newObject = true; for ($j = 0, $resCount = count($results); $j < $resCount; $j++) { $temp_obj1 = $results[$j]; $temp_obj2 = $temp_obj1->getUser(); //CHECKME if ($temp_obj2->getPrimaryKey() === $obj2->getPrimaryKey()) { $newObject = false; $temp_obj2->addFileImportHistory($obj1); break; } } if ($newObject) { $obj2->initFileImportHistorys(); $obj2->addFileImportHistory($obj1); } $omClass = VocabularyPeer::getOMClass(); $cls = Propel::import($omClass); $obj3 = new $cls(); $obj3->hydrate($rs, $startcol3); $newObject = true; for ($j = 0, $resCount = count($results); $j < $resCount; $j++) { $temp_obj1 = $results[$j]; $temp_obj3 = $temp_obj1->getVocabulary(); //CHECKME if ($temp_obj3->getPrimaryKey() === $obj3->getPrimaryKey()) { $newObject = false; $temp_obj3->addFileImportHistory($obj1); break; } } if ($newObject) { $obj3->initFileImportHistorys(); $obj3->addFileImportHistory($obj1); } $omClass = SchemaPeer::getOMClass(); $cls = Propel::import($omClass); $obj4 = new $cls(); $obj4->hydrate($rs, $startcol4); $newObject = true; for ($j = 0, $resCount = count($results); $j < $resCount; $j++) { $temp_obj1 = $results[$j]; $temp_obj4 = $temp_obj1->getSchema(); //CHECKME if ($temp_obj4->getPrimaryKey() === $obj4->getPrimaryKey()) { $newObject = false; $temp_obj4->addFileImportHistory($obj1); break; } } if ($newObject) { $obj4->initFileImportHistorys(); $obj4->addFileImportHistory($obj1); } $results[] = $obj1; } return $results; }
/** * Selects a collection of Discuss objects pre-filled with all related objects except DiscussRelatedByParentId. * * @return array Array of Discuss objects. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doSelectJoinAllExceptDiscussRelatedByParentId(Criteria $c, $con = null) { $c = clone $c; // Set the correct dbName if it has not been overridden // $c->getDbName() will return the same object if not set to another value // so == check is okay and faster if ($c->getDbName() == Propel::getDefaultDB()) { $c->setDbName(self::DATABASE_NAME); } DiscussPeer::addSelectColumns($c); $startcol2 = DiscussPeer::NUM_COLUMNS - DiscussPeer::NUM_LAZY_LOAD_COLUMNS + 1; UserPeer::addSelectColumns($c); $startcol3 = $startcol2 + UserPeer::NUM_COLUMNS; UserPeer::addSelectColumns($c); $startcol4 = $startcol3 + UserPeer::NUM_COLUMNS; SchemaPeer::addSelectColumns($c); $startcol5 = $startcol4 + SchemaPeer::NUM_COLUMNS; SchemaPropertyPeer::addSelectColumns($c); $startcol6 = $startcol5 + SchemaPropertyPeer::NUM_COLUMNS; SchemaPropertyElementPeer::addSelectColumns($c); $startcol7 = $startcol6 + SchemaPropertyElementPeer::NUM_COLUMNS; VocabularyPeer::addSelectColumns($c); $startcol8 = $startcol7 + VocabularyPeer::NUM_COLUMNS; ConceptPeer::addSelectColumns($c); $startcol9 = $startcol8 + ConceptPeer::NUM_COLUMNS; ConceptPropertyPeer::addSelectColumns($c); $startcol10 = $startcol9 + ConceptPropertyPeer::NUM_COLUMNS; $c->addJoin(DiscussPeer::CREATED_USER_ID, UserPeer::ID); $c->addJoin(DiscussPeer::DELETED_USER_ID, UserPeer::ID); $c->addJoin(DiscussPeer::SCHEMA_ID, SchemaPeer::ID); $c->addJoin(DiscussPeer::SCHEMA_PROPERTY_ID, SchemaPropertyPeer::ID); $c->addJoin(DiscussPeer::SCHEMA_PROPERTY_ELEMENT_ID, SchemaPropertyElementPeer::ID); $c->addJoin(DiscussPeer::VOCABULARY_ID, VocabularyPeer::ID); $c->addJoin(DiscussPeer::CONCEPT_ID, ConceptPeer::ID); $c->addJoin(DiscussPeer::CONCEPT_PROPERTY_ID, ConceptPropertyPeer::ID); $rs = BasePeer::doSelect($c, $con); $results = array(); while ($rs->next()) { $omClass = DiscussPeer::getOMClass(); $cls = Propel::import($omClass); $obj1 = new $cls(); $obj1->hydrate($rs); $omClass = UserPeer::getOMClass(); $cls = Propel::import($omClass); $obj2 = new $cls(); $obj2->hydrate($rs, $startcol2); $newObject = true; for ($j = 0, $resCount = count($results); $j < $resCount; $j++) { $temp_obj1 = $results[$j]; $temp_obj2 = $temp_obj1->getUserRelatedByCreatedUserId(); //CHECKME if ($temp_obj2->getPrimaryKey() === $obj2->getPrimaryKey()) { $newObject = false; $temp_obj2->addDiscussRelatedByCreatedUserId($obj1); break; } } if ($newObject) { $obj2->initDiscusssRelatedByCreatedUserId(); $obj2->addDiscussRelatedByCreatedUserId($obj1); } $omClass = UserPeer::getOMClass(); $cls = Propel::import($omClass); $obj3 = new $cls(); $obj3->hydrate($rs, $startcol3); $newObject = true; for ($j = 0, $resCount = count($results); $j < $resCount; $j++) { $temp_obj1 = $results[$j]; $temp_obj3 = $temp_obj1->getUserRelatedByDeletedUserId(); //CHECKME if ($temp_obj3->getPrimaryKey() === $obj3->getPrimaryKey()) { $newObject = false; $temp_obj3->addDiscussRelatedByDeletedUserId($obj1); break; } } if ($newObject) { $obj3->initDiscusssRelatedByDeletedUserId(); $obj3->addDiscussRelatedByDeletedUserId($obj1); } $omClass = SchemaPeer::getOMClass(); $cls = Propel::import($omClass); $obj4 = new $cls(); $obj4->hydrate($rs, $startcol4); $newObject = true; for ($j = 0, $resCount = count($results); $j < $resCount; $j++) { $temp_obj1 = $results[$j]; $temp_obj4 = $temp_obj1->getSchema(); //CHECKME if ($temp_obj4->getPrimaryKey() === $obj4->getPrimaryKey()) { $newObject = false; $temp_obj4->addDiscuss($obj1); break; } } if ($newObject) { $obj4->initDiscusss(); $obj4->addDiscuss($obj1); } $omClass = SchemaPropertyPeer::getOMClass(); $cls = Propel::import($omClass); $obj5 = new $cls(); $obj5->hydrate($rs, $startcol5); $newObject = true; for ($j = 0, $resCount = count($results); $j < $resCount; $j++) { $temp_obj1 = $results[$j]; $temp_obj5 = $temp_obj1->getSchemaProperty(); //CHECKME if ($temp_obj5->getPrimaryKey() === $obj5->getPrimaryKey()) { $newObject = false; $temp_obj5->addDiscuss($obj1); break; } } if ($newObject) { $obj5->initDiscusss(); $obj5->addDiscuss($obj1); } $omClass = SchemaPropertyElementPeer::getOMClass(); $cls = Propel::import($omClass); $obj6 = new $cls(); $obj6->hydrate($rs, $startcol6); $newObject = true; for ($j = 0, $resCount = count($results); $j < $resCount; $j++) { $temp_obj1 = $results[$j]; $temp_obj6 = $temp_obj1->getSchemaPropertyElement(); //CHECKME if ($temp_obj6->getPrimaryKey() === $obj6->getPrimaryKey()) { $newObject = false; $temp_obj6->addDiscuss($obj1); break; } } if ($newObject) { $obj6->initDiscusss(); $obj6->addDiscuss($obj1); } $omClass = VocabularyPeer::getOMClass(); $cls = Propel::import($omClass); $obj7 = new $cls(); $obj7->hydrate($rs, $startcol7); $newObject = true; for ($j = 0, $resCount = count($results); $j < $resCount; $j++) { $temp_obj1 = $results[$j]; $temp_obj7 = $temp_obj1->getVocabulary(); //CHECKME if ($temp_obj7->getPrimaryKey() === $obj7->getPrimaryKey()) { $newObject = false; $temp_obj7->addDiscuss($obj1); break; } } if ($newObject) { $obj7->initDiscusss(); $obj7->addDiscuss($obj1); } $omClass = ConceptPeer::getOMClass(); $cls = Propel::import($omClass); $obj8 = new $cls(); $obj8->hydrate($rs, $startcol8); $newObject = true; for ($j = 0, $resCount = count($results); $j < $resCount; $j++) { $temp_obj1 = $results[$j]; $temp_obj8 = $temp_obj1->getConcept(); //CHECKME if ($temp_obj8->getPrimaryKey() === $obj8->getPrimaryKey()) { $newObject = false; $temp_obj8->addDiscuss($obj1); break; } } if ($newObject) { $obj8->initDiscusss(); $obj8->addDiscuss($obj1); } $omClass = ConceptPropertyPeer::getOMClass(); $cls = Propel::import($omClass); $obj9 = new $cls(); $obj9->hydrate($rs, $startcol9); $newObject = true; for ($j = 0, $resCount = count($results); $j < $resCount; $j++) { $temp_obj1 = $results[$j]; $temp_obj9 = $temp_obj1->getConceptProperty(); //CHECKME if ($temp_obj9->getPrimaryKey() === $obj9->getPrimaryKey()) { $newObject = false; $temp_obj9->addDiscuss($obj1); break; } } if ($newObject) { $obj9->initDiscusss(); $obj9->addDiscuss($obj1); } $results[] = $obj1; } return $results; }
/** * @return string * @throws sfError404Exception */ public function executeGet() { /** @var myWebRequest $request **/ $request = $this->getRequest(); $redir = $this->getRequestParameter('redir', false); $uri = $this->getRequestParameter('uri'); if (!$uri) { $uri = "http://" . $request->getPathInfoParam('HTTP_HOST') . $request->getPathInfoParam('REQUEST_URI'); //strip trailing type $uri = preg_replace('/\\.\\w+$/U', '', $uri); //strip _dev script if it's part of the URI' $uri = preg_replace('%\\w+\\_dev.php/%', '', $uri); } $module = $this->getRequestParameter('type'); if ('unknown' == $module) { $accept = $request->getPathInfoParam('HTTP_ACCEPT'); $agent = $request->getPathInfoParam('HTTP_USER_AGENT'); //any of these will return html /*RewriteCond %{HTTP_ACCEPT} !application/rdf\+xml.*(text/html|application/xhtml\+xml) RewriteCond %{HTTP_ACCEPT} text/html [OR] RewriteCond %{HTTP_ACCEPT} application/xhtml\+xml [OR] RewriteCond %{HTTP_USER_AGENT} ^Mozilla/.* RewriteRule ^(.*)$ rdtest.php?type=html&uri=$1 [QSA,L] */ if (!preg_match('%application/rdf\\+xml.*(text/html|application/xhtml\\+xml)%im', $accept) && (preg_match('%text/html%im', $accept) || preg_match('%application/xhtml\\+xml%im', $accept) || preg_match('%^Mozilla/.*%im', $agent) && preg_match('%\\*/\\*%im', $accept))) { $module = 'html'; } elseif (preg_match('%application/rdf\\+xml%im', $accept)) { $module = 'rdf'; } elseif (preg_match('%text/rdf+n3%im', $accept)) { $module = 'n3'; } else { $module = sfConfig::get('default_conneg_type'); } } $class = strtolower($this->getRequestParameter('class')); switch ($class) { case 'concept': switch ($module) { case 'html': /** @var Concept $concept **/ $concept = ConceptPeer::getConceptByUri($uri); $this->forward404Unless($concept); $uri = $request->getUriPrefix() . "/concept/show/id/" . $concept->getId() . ".html"; //redirect $this->redirectIf($redir, $uri, 303); //return the url return $this->renderText($uri); //forward //$request->setParameter('vocabulary_id', $vocabulary->getId()); //$this->forward('concept','list'); break; case 'rdf': //redirect $this->redirectIf($redir, $uri . '.rdf', 303); //forward $request->setParameter('type', 'api_uri'); $this->forwardIf($uri, 'rdf', 'showConcept'); break; } break; case 'concept_scheme': case 'conceptscheme': switch ($module) { case 'html': /** @var Vocabulary $vocabulary **/ $vocabulary = VocabularyPeer::retrieveByUri($uri); $this->forward404Unless($vocabulary); $uri = $request->getUriPrefix() . "/vocabulary/show/id/" . $vocabulary->getId() . ".html"; //redirect $this->redirectIf($redir, $uri, 303); //return the url return $this->renderText($uri); //forward //$request->setParameter('vocabulary_id', $vocabulary->getId()); //$this->forward('concept','list'); break; case 'rdf': //redirect $this->redirectIf($redir, $uri . '.rdf', 303); //forward $request->setParameter('type', 'api_uri'); $this->forwardIf($uri, 'rdf', 'showScheme'); break; case 'xsd': //reset the type $request->setParameter('type', 'api_uri'); $this->forwardIf($uri, 'xml', 'showScheme'); break; } break; case 'schema': /** @var Schema $schema **/ $schema = SchemaPeer::retrieveByUri($uri); $this->forward404Unless($schema); switch ($module) { case 'html': $uri = $request->getUriPrefix() . "/schema/show/id/" . $schema->getId() . ".html"; //redirect $this->redirectIf($redir, $uri, 303); //return the url return $this->renderText($uri); break; case 'rdf': //redirect $this->redirectIf($redir, $uri . '.rdf', 303); //forward $request->setParameter('id', $schema->getId()); $this->forwardIf($uri, 'schema', 'showRdf'); break; } break; case 'schema_property': case 'schemaproperty': /** @var SchemaProperty $property **/ $property = SchemaPropertyPeer::retrieveByUri($uri); $this->forward404Unless($property); switch ($module) { case 'html': $uri = $request->getUriPrefix() . "/schemaprop/show/id/" . $property->getId() . ".html"; //redirect $this->redirectIf($redir, $uri, 303); //return the url return $this->renderText($uri); break; case 'rdf': //redirect $this->redirectIf($redir, $uri . '.rdf', 303); //forward $request->setParameter('id', $property->getId()); $this->forwardIf($uri, 'schemaprop', 'showRdf'); break; } break; default: $this->forward404(); } return sfView::NONE; }
public function setSchema( $schemaId ) { if ($this->type === 'schema' ) { $this->schema = \SchemaPeer::retrieveByPK($schemaId); } else { $this->schema = \VocabularyPeer::retrieveByPK($schemaId); } }
public function perform($args) { list($schemaId, $filePath, $importId, $environment, $type) = $args; // Set up environment for this job define('SF_ROOT_DIR', realpath(dirname(__file__) . '/../../../..')); define('SF_APP', 'frontend'); define('SF_ENVIRONMENT', $environment); define('SF_DEBUG', false); //initialize composer require_once(SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php'); // initialize symfony require_once(SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php'); // initialize database manager $databaseManager = new \sfDatabaseManager(); $databaseManager->initialize(); $import = new ImportVocab($type, $filePath, $schemaId); try { $fileImportHistory = \FileImportHistoryPeer::retrieveByPK($importId); } catch (\PropelException $e) { //exit the job with an error throw $e; } try { if ('schema' == $type) { $schema = \SchemaPeer::retrieveByPK($schemaId); } else { $schema = \VocabularyPeer::retrieveByPK($schemaId); } } catch (\PropelException $e) { //exit the job with an error throw $e; } // Perform some job $import->importId = $importId; //todo update the prefixes table with prefixes //todo update the schema table with prefixes $schemaPrefixes = $schema->getPrefixes(); $countSchemaPrefixes = count($schemaPrefixes); /** @var string[] $importPrefixes */ $importPrefixes = $import->prolog['prefix']; foreach ($importPrefixes as $prefix => $url) { if (trim($prefix)) { if ( ! array_key_exists($prefix, $schemaPrefixes)) { $schemaPrefixes[$prefix] = $url; } } } if (count($schemaPrefixes) != $countSchemaPrefixes) { $schema->setPrefixes($schemaPrefixes); $schema->save(); } try { $prolog = $import->processProlog(); $import->processData(); $fileImportHistory->setResults($import->results); $fileImportHistory->setMap($import->mapping); $fileImportHistory->setTotalProcessedCount( $import->DataWorkflowResults->getTotalProcessedCount()); $fileImportHistory->setErrorCount($import->DataWorkflowResults->getErrorCount()); $fileImportHistory->setSuccessCount($import->DataWorkflowResults->getSuccessCount()); $fileImportHistory->setResults('Your file has been imported. It took us: ' . $import->DataWorkflowResults->getElapsed()->format("%h hours; %i minutes; %s seconds")); $fileImportHistory->save(); } catch (\Exception $e) { $fileImportHistory->setResults("There was an error processing the import. Message: " . $e->getMessage()); $fileImportHistory->save(); throw $e; } $agentId = ($fileImportHistory->getSchema()) ? $fileImportHistory->getSchema()->getAgentId() : $fileImportHistory->getVocabulary()->getAgentId(); $newFilePath = \sfConfig::get( 'sf_repos_dir' ) . DIRECTORY_SEPARATOR . 'agents' . DIRECTORY_SEPARATOR . $agentId . DIRECTORY_SEPARATOR . $fileImportHistory->getSourceFileName(); $request = new \myWebRequest(); $result = $request->moveToRepo($filePath, $newFilePath); $schema = \SchemaPeer::retrieveByPK($schemaId); if ($schema) { $schema->setUpdatedAt(time()); $schema->setUpdatedUserId($import->userId); $schema->save(); } unset ($import); unset ($request); unset($databaseManager); }
/** * Populates the object using an array. * * This is particularly useful when populating an object from one of the * request arrays (e.g. $_POST). This method goes through the column * names, checking to see whether a matching key exists in populated * array. If so the setByName() method is called for that column. * * You can specify the key type of the array by additionally passing one * of the class type constants TYPE_PHPNAME, TYPE_COLNAME, TYPE_FIELDNAME, * TYPE_NUM. The default key type is the column's phpname (e.g. 'authorId') * * @param array $arr An array to populate the object from. * @param string $keyType The type of keys the array uses. * @return void */ public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME) { $keys = SchemaPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setAgentId($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setCreatedAt($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setUpdatedAt($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { $this->setDeletedAt($arr[$keys[4]]); } if (array_key_exists($keys[5], $arr)) { $this->setCreatedUserId($arr[$keys[5]]); } if (array_key_exists($keys[6], $arr)) { $this->setUpdatedUserId($arr[$keys[6]]); } if (array_key_exists($keys[7], $arr)) { $this->setChildUpdatedAt($arr[$keys[7]]); } if (array_key_exists($keys[8], $arr)) { $this->setChildUpdatedUserId($arr[$keys[8]]); } if (array_key_exists($keys[9], $arr)) { $this->setName($arr[$keys[9]]); } if (array_key_exists($keys[10], $arr)) { $this->setNote($arr[$keys[10]]); } if (array_key_exists($keys[11], $arr)) { $this->setUri($arr[$keys[11]]); } if (array_key_exists($keys[12], $arr)) { $this->setUrl($arr[$keys[12]]); } if (array_key_exists($keys[13], $arr)) { $this->setBaseDomain($arr[$keys[13]]); } if (array_key_exists($keys[14], $arr)) { $this->setToken($arr[$keys[14]]); } if (array_key_exists($keys[15], $arr)) { $this->setCommunity($arr[$keys[15]]); } if (array_key_exists($keys[16], $arr)) { $this->setLastUriId($arr[$keys[16]]); } if (array_key_exists($keys[17], $arr)) { $this->setStatusId($arr[$keys[17]]); } if (array_key_exists($keys[18], $arr)) { $this->setLanguage($arr[$keys[18]]); } if (array_key_exists($keys[19], $arr)) { $this->setProfileId($arr[$keys[19]]); } if (array_key_exists($keys[20], $arr)) { $this->setNsType($arr[$keys[20]]); } if (array_key_exists($keys[21], $arr)) { $this->setPrefixes($arr[$keys[21]]); } if (array_key_exists($keys[22], $arr)) { $this->setLanguages($arr[$keys[22]]); } if (array_key_exists($keys[23], $arr)) { $this->setRepo($arr[$keys[23]]); } }
/** * description * * @return Schema Current schema object * * @param int $schemaId */ public static function setLatestSchema($schemaId) { if (is_object($schemaId)) { $schemaObj = $schemaId; } else { $schemaObj = SchemaPeer::retrieveByPK($schemaId); } if ($schemaObj) { sfContext::getInstance()->getUser()->setCurrentSchema($schemaObj); return $schemaObj; } else { return false; } }
private function getDefaultLanguage($textual = false) { $language = 'en'; if (!$this->schema) { $this->schema = SchemaPeer::retrieveByPk($this->getRequestParameter('id')); } if (isset($this->schema)) { $language = $this->schema->getLanguage(); } if (!$textual) { return $language; } else { $culture = 'en'; /** @var myUser $user */ $user = $this->getUser(); if ($user) { $culture = $user->getCulture(); } $cultureInfo = new sfCultureInfo($culture); $languages = $cultureInfo->getLanguages(); return $languages[$language]; } }
/** * Selects a collection of SchemaPropertyElementHistory objects pre-filled with all related objects except FileImportHistory. * * @return array Array of SchemaPropertyElementHistory objects. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doSelectJoinAllExceptFileImportHistory(Criteria $c, $con = null) { $c = clone $c; // Set the correct dbName if it has not been overridden // $c->getDbName() will return the same object if not set to another value // so == check is okay and faster if ($c->getDbName() == Propel::getDefaultDB()) { $c->setDbName(self::DATABASE_NAME); } SchemaPropertyElementHistoryPeer::addSelectColumns($c); $startcol2 = SchemaPropertyElementHistoryPeer::NUM_COLUMNS - SchemaPropertyElementHistoryPeer::NUM_LAZY_LOAD_COLUMNS + 1; UserPeer::addSelectColumns($c); $startcol3 = $startcol2 + UserPeer::NUM_COLUMNS; SchemaPropertyElementPeer::addSelectColumns($c); $startcol4 = $startcol3 + SchemaPropertyElementPeer::NUM_COLUMNS; SchemaPropertyPeer::addSelectColumns($c); $startcol5 = $startcol4 + SchemaPropertyPeer::NUM_COLUMNS; SchemaPeer::addSelectColumns($c); $startcol6 = $startcol5 + SchemaPeer::NUM_COLUMNS; ProfilePropertyPeer::addSelectColumns($c); $startcol7 = $startcol6 + ProfilePropertyPeer::NUM_COLUMNS; SchemaPropertyPeer::addSelectColumns($c); $startcol8 = $startcol7 + SchemaPropertyPeer::NUM_COLUMNS; StatusPeer::addSelectColumns($c); $startcol9 = $startcol8 + StatusPeer::NUM_COLUMNS; $c->addJoin(SchemaPropertyElementHistoryPeer::CREATED_USER_ID, UserPeer::ID); $c->addJoin(SchemaPropertyElementHistoryPeer::SCHEMA_PROPERTY_ELEMENT_ID, SchemaPropertyElementPeer::ID); $c->addJoin(SchemaPropertyElementHistoryPeer::SCHEMA_PROPERTY_ID, SchemaPropertyPeer::ID); $c->addJoin(SchemaPropertyElementHistoryPeer::SCHEMA_ID, SchemaPeer::ID); $c->addJoin(SchemaPropertyElementHistoryPeer::PROFILE_PROPERTY_ID, ProfilePropertyPeer::ID); $c->addJoin(SchemaPropertyElementHistoryPeer::RELATED_SCHEMA_PROPERTY_ID, SchemaPropertyPeer::ID); $c->addJoin(SchemaPropertyElementHistoryPeer::STATUS_ID, StatusPeer::ID); $rs = BasePeer::doSelect($c, $con); $results = array(); while ($rs->next()) { $omClass = SchemaPropertyElementHistoryPeer::getOMClass(); $cls = Propel::import($omClass); $obj1 = new $cls(); $obj1->hydrate($rs); $omClass = UserPeer::getOMClass(); $cls = Propel::import($omClass); $obj2 = new $cls(); $obj2->hydrate($rs, $startcol2); $newObject = true; for ($j = 0, $resCount = count($results); $j < $resCount; $j++) { $temp_obj1 = $results[$j]; $temp_obj2 = $temp_obj1->getUser(); //CHECKME if ($temp_obj2->getPrimaryKey() === $obj2->getPrimaryKey()) { $newObject = false; $temp_obj2->addSchemaPropertyElementHistory($obj1); break; } } if ($newObject) { $obj2->initSchemaPropertyElementHistorys(); $obj2->addSchemaPropertyElementHistory($obj1); } $omClass = SchemaPropertyElementPeer::getOMClass(); $cls = Propel::import($omClass); $obj3 = new $cls(); $obj3->hydrate($rs, $startcol3); $newObject = true; for ($j = 0, $resCount = count($results); $j < $resCount; $j++) { $temp_obj1 = $results[$j]; $temp_obj3 = $temp_obj1->getSchemaPropertyElement(); //CHECKME if ($temp_obj3->getPrimaryKey() === $obj3->getPrimaryKey()) { $newObject = false; $temp_obj3->addSchemaPropertyElementHistory($obj1); break; } } if ($newObject) { $obj3->initSchemaPropertyElementHistorys(); $obj3->addSchemaPropertyElementHistory($obj1); } $omClass = SchemaPropertyPeer::getOMClass(); $cls = Propel::import($omClass); $obj4 = new $cls(); $obj4->hydrate($rs, $startcol4); $newObject = true; for ($j = 0, $resCount = count($results); $j < $resCount; $j++) { $temp_obj1 = $results[$j]; $temp_obj4 = $temp_obj1->getSchemaPropertyRelatedBySchemaPropertyId(); //CHECKME if ($temp_obj4->getPrimaryKey() === $obj4->getPrimaryKey()) { $newObject = false; $temp_obj4->addSchemaPropertyElementHistoryRelatedBySchemaPropertyId($obj1); break; } } if ($newObject) { $obj4->initSchemaPropertyElementHistorysRelatedBySchemaPropertyId(); $obj4->addSchemaPropertyElementHistoryRelatedBySchemaPropertyId($obj1); } $omClass = SchemaPeer::getOMClass(); $cls = Propel::import($omClass); $obj5 = new $cls(); $obj5->hydrate($rs, $startcol5); $newObject = true; for ($j = 0, $resCount = count($results); $j < $resCount; $j++) { $temp_obj1 = $results[$j]; $temp_obj5 = $temp_obj1->getSchema(); //CHECKME if ($temp_obj5->getPrimaryKey() === $obj5->getPrimaryKey()) { $newObject = false; $temp_obj5->addSchemaPropertyElementHistory($obj1); break; } } if ($newObject) { $obj5->initSchemaPropertyElementHistorys(); $obj5->addSchemaPropertyElementHistory($obj1); } $omClass = ProfilePropertyPeer::getOMClass(); $cls = Propel::import($omClass); $obj6 = new $cls(); $obj6->hydrate($rs, $startcol6); $newObject = true; for ($j = 0, $resCount = count($results); $j < $resCount; $j++) { $temp_obj1 = $results[$j]; $temp_obj6 = $temp_obj1->getProfileProperty(); //CHECKME if ($temp_obj6->getPrimaryKey() === $obj6->getPrimaryKey()) { $newObject = false; $temp_obj6->addSchemaPropertyElementHistory($obj1); break; } } if ($newObject) { $obj6->initSchemaPropertyElementHistorys(); $obj6->addSchemaPropertyElementHistory($obj1); } $omClass = SchemaPropertyPeer::getOMClass(); $cls = Propel::import($omClass); $obj7 = new $cls(); $obj7->hydrate($rs, $startcol7); $newObject = true; for ($j = 0, $resCount = count($results); $j < $resCount; $j++) { $temp_obj1 = $results[$j]; $temp_obj7 = $temp_obj1->getSchemaPropertyRelatedByRelatedSchemaPropertyId(); //CHECKME if ($temp_obj7->getPrimaryKey() === $obj7->getPrimaryKey()) { $newObject = false; $temp_obj7->addSchemaPropertyElementHistoryRelatedByRelatedSchemaPropertyId($obj1); break; } } if ($newObject) { $obj7->initSchemaPropertyElementHistorysRelatedByRelatedSchemaPropertyId(); $obj7->addSchemaPropertyElementHistoryRelatedByRelatedSchemaPropertyId($obj1); } $omClass = StatusPeer::getOMClass(); $cls = Propel::import($omClass); $obj8 = new $cls(); $obj8->hydrate($rs, $startcol8); $newObject = true; for ($j = 0, $resCount = count($results); $j < $resCount; $j++) { $temp_obj1 = $results[$j]; $temp_obj8 = $temp_obj1->getStatus(); //CHECKME if ($temp_obj8->getPrimaryKey() === $obj8->getPrimaryKey()) { $newObject = false; $temp_obj8->addSchemaPropertyElementHistory($obj1); break; } } if ($newObject) { $obj8->initSchemaPropertyElementHistorys(); $obj8->addSchemaPropertyElementHistory($obj1); } $results[] = $obj1; } return $results; }
public function setVocabularyParams() { //use the prolog to look up correct resources in the database if ('schema' == $this->type) { $vocabulary = \SchemaPeer::retrieveByPK($this->vocabId); } else { /** @var $vocabulary \Vocabulary */ $vocabulary = \VocabularyPeer::retrieveByPK($this->vocabId); } if ( ! $vocabulary) { //TODO: turn this into a real error message and exit gracefully exit( "No vocab!!!!!" ); } $this->vocabulary = $vocabulary; //if we didn't set it from the constructor we set default status from the vocab if ( ! $this->status) { $this->prolog['defaults']['statusId'] = $this->getStatusId($vocabulary->getStatusId()); } else { $this->prolog['defaults']['statusId'] = $this->status; } //if the prolog never set the default language from the spreadsheet, set it here if ( ! isset( $this->prolog['defaults']['lang'] )) { $this->prolog['defaults']['lang'] = $vocabulary->getLanguage(); } //if it hasn't been set already, set the userId from the vocabulary (which does a little bit more work) if ( ! $this->userId) { $this->setUserId(); } }
/** * gets the current schema object * * @return schema current schema object */ public function getCurrentSchema() { $schema = false; if ($this->getRequestParameter('id')) { $this->file_import_history = FileImportHistoryPeer::retrieveByPk($this->getRequestParameter('id')); if (isset($this->file_import_history)) { $schema = $this->file_import_history->getSchema(); if ($this->file_import_history->getSchemaId()) { $schema = $this->file_import_history->getSchema(); } if ($this->file_import_history->getVocabularyId()) { $schema = $this->file_import_history->getVocabulary(); } } } if ($this->getRequestParameter('schema_id')) { $schema = SchemaPeer::retrieveByPk($this->getRequestParameter('schema_id')); $this->type = 'schema'; } if ($this->getRequestParameter('vocabulary_id')) { $schema = VocabularyPeer::retrieveByPk($this->getRequestParameter('vocabulary_id')); $this->type = 'vocabulary'; } if ($schema) { myActionTools::setLatestSchema($schema->getId()); } $this->forward404Unless($schema, 'No filter has been selected.'); $this->schema = $schema; $this->schemaID = $schema->getId(); return $schema; }
//foreach vocabulary /** @var Vocabulary $vocabulary **/ foreach ($rs as $vocabulary) { $query = 'LOAD <http://' . $_SERVER['HTTP_HOST'] . '/vocabulary/show/id/' . $vocabulary->getId() . '.rdf> INTO <' . $vocabulary->getUri() . '>'; $result = $batchLog->createBatchRecord($batchTime, $batchDescription, $batchObjectType, $query, "query", $vocabulary->getId(), $vocabulary->getUri()); $store->clearErrors(); $rs = $store->query($query); if ($errs = $store->getErrors()) { foreach ($errs as $key => $value) { $result = $batchLog->createBatchRecord($batchTime, $batchDescription, $batchObjectType, $value, "error", $vocabulary->getId(), $vocabulary->getUri()); } } } $result = $batchLog->createBatchRecord($batchTime, $batchDescription, $batchObjectType, "Finish Vocabulary run", "finish"); //get the element sets $foo = new SchemaPeer(); $selectCriteria = new Criteria(SchemaPeer::DATABASE_NAME); $rs = $foo->doSelect($selectCriteria); $batchObjectType = "schema"; $result = $batchLog->createBatchRecord($batchTime, $batchDescription, $batchObjectType, "Starting Element Set run", "init"); //foreach vocabulary /** @var Schema $vocabulary **/ foreach ($rs as $vocabulary) { $query = 'LOAD <http://' . $_SERVER['HTTP_HOST'] . '/schema/show/id/' . $vocabulary->getId() . '.rdf> INTO <' . $vocabulary->getUri() . '>'; $result = $batchLog->createBatchRecord($batchTime, $batchDescription, $batchObjectType, $query, "query", $vocabulary->getId(), $vocabulary->getUri()); $store->clearErrors(); $rs = $store->query($query); if ($errs = $store->getErrors()) { foreach ($errs as $key => $value) { $result = $batchLog->createBatchRecord($batchTime, $batchDescription, $batchObjectType, $value, "error", $vocabulary->getId(), $vocabulary->getUri()); }
/** * Get the associated Schema object * * @param Connection Optional Connection object. * @return Schema The associated Schema object. * @throws PropelException */ public function getSchema($con = null) { if ($this->aSchema === null && $this->schema_id !== null) { // include the related Peer class include_once 'lib/model/om/BaseSchemaPeer.php'; $this->aSchema = SchemaPeer::retrieveByPK($this->schema_id, $con); /* The following can be used instead of the line above to guarantee the related object contains a reference to this object, but this level of coupling may be undesirable in many circumstances. As it can lead to a db query with many results that may never be used. $obj = SchemaPeer::retrieveByPK($this->schema_id, $con); $obj->addSchemas($this); */ } return $this->aSchema; }
/** * Selects a collection of RdfNamespace objects pre-filled with all related objects. * * @return array Array of RdfNamespace objects. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doSelectJoinAll(Criteria $c, $con = null) { $c = clone $c; // Set the correct dbName if it has not been overridden if ($c->getDbName() == Propel::getDefaultDB()) { $c->setDbName(self::DATABASE_NAME); } RdfNamespacePeer::addSelectColumns($c); $startcol2 = RdfNamespacePeer::NUM_COLUMNS - RdfNamespacePeer::NUM_LAZY_LOAD_COLUMNS + 1; SchemaPeer::addSelectColumns($c, 'a1'); $startcol3 = $startcol2 + SchemaPeer::NUM_COLUMNS; $c->addJoin(RdfNamespacePeer::SCHEMA_ID, SchemaPeer::alias('a1', SchemaPeer::ID)); $c->addAlias('a1', SchemaPeer::TABLE_NAME); $rs = BasePeer::doSelect($c, $con); $results = array(); while ($rs->next()) { $omClass = RdfNamespacePeer::getOMClass(); $cls = Propel::import($omClass); $obj1 = new $cls(); $obj1->hydrate($rs); // Add objects for joined Schema rows $omClass = SchemaPeer::getOMClass(); $cls = Propel::import($omClass); $obj2 = new $cls(); $obj2->hydrate($rs, $startcol2); $newObject = true; for ($j = 0, $resCount = count($results); $j < $resCount; $j++) { $temp_obj1 = $results[$j]; $temp_obj2 = $temp_obj1->getSchema(); // CHECKME if ($temp_obj2->getPrimaryKey() === $obj2->getPrimaryKey()) { $newObject = false; $temp_obj2->addRdfNamespace($obj1); // CHECKME break; } } if ($newObject) { $obj2->initRdfNamespaces(); $obj2->addRdfNamespace($obj1); } $results[] = $obj1; } return $results; }
/** * this is for importing a list of value vocabulary files. * * it's designed specifically to import the list of marc21 VES files, * but may be modified and expanded to support more things * * @param $task * @param $args * * @throws Exception */ function run_import_list($task, $args) { xdebug_break(); //check the argument counts //check the argument counts if (count($args) < 1) { throw new Exception('You must provide a vocabulary type.'); } if (count($args) < 2) { throw new Exception('You must provide a file name.'); } //set the arguments $type = strtolower($args[0]); $filePath = $args[1]; $batchId = $args[3]; //does the file exist? if (! file_exists($filePath)) { throw new Exception('You must supply a valid file to import'); } //is the file a valid type? if (preg_match('/^.+\.([[:alpha:]]{2,4})$/', $filePath, $matches)) { if (! in_array( strtolower($matches[1]), array( "json", "rdf", "csv", "xml" ) ) ) { throw new Exception('You must provide a valid file type based on the extension'); } } else { throw new Exception("File type cannot be determined from the file extension"); } /************************************************************ * Set Defaults Here * *************************************************************/ $fileType = $matches[1]; //todo: need to figure out a way to pass defaults dynamically $importTask = new pakeTask('import-vocabulary'); // parse file to get the fields/columns and data $file = fopen($filePath, "r"); if (! $file) { throw new Exception("Can't read supplied file"); } switch ($fileType) { case "csv": try { $reader = new aCsvReader($filePath); } catch(Exception $e) { throw new Exception("Not a happy CSV file! Error: " . $e); } $uploadPath = $GLOBALS['uploadPath']; ; if ('vocab' == $type) { // Get array of heading names found $headings = $reader->getHeadings(); $fields = VocabularyPeer::getFieldNames(); try { while ($row = $reader->getRow()) { // lookup the URI (or the OMR ID if available) for a match if (empty($row["VES"])) { //skip this one break; } $uri = $baseDomain . $row["VES"] . "#"; $vocab = VocabularyPeer::getVocabularyByUri($uri); $updateTime = time(); if (! $vocab) { // create a new concept or element $vocab = new Vocabulary(); $vocab->setUri($uri); $vocab->setCreatedAt($updateTime); $vocab->setCreatedUserId($userId); $vocab->setAgentId($agentID); $vocab->setBaseDomain($baseDomain); $vocab->setCommunity("Libraries, MARC21"); $vocab->setLanguage("en"); $vocab->setStatusId(1); } else { $vocab->setLastUpdated($updateTime); $vocab->setUpdatedUserId($userId); } $vocab->setName(fixEncoding(rtrim($row['Name']))); $vocab->setNote(fixEncoding(rtrim($row['Note']))); $vocab->setToken($row['VES']); $vocab->save(); //type $args[0] = "vocab"; //vocabid $args[2] = $vocab->getId(); //filepath $args[1] = $GLOBALS['uploadPath'] . $row['VES'] . ".csv"; $args[3] = $batchId; $args[4] = "-d"; run_import_vocabulary($importTask, $args); $foo = $vocab->countConcepts(); } } catch(Exception $e) { throw new Exception($e); } } else //it's a schema { try { while ($row = $reader->getRow()) { //NOTE: this is explicitly tuned to a particular import file //TODO: generalize this import mapping // lookup the URI (or the OMR ID if available) for a match if (empty($row["URI"])) { //skip this one break; } $uri = $row["URI"]; $schema = SchemaPeer::getschemaByUri($uri); $updateTime = time(); if (! $schema) { // create a new vocabulary $schema = new Schema(); $schema->setUri($uri); $schema->setCreatedAt($updateTime); $schema->setCreatedUserId($userId); $schema->setAgentId($agentID); $schema->setBaseDomain($baseDomain); $schema->setProfileId(1); } else { $schema->setUpdatedAt($updateTime); $schema->setUpdatedUserId($userId); } $schema->setCommunity($row['Tags']); $schema->setLanguage($row['Language']); $schema->setNsType("slash"); $schema->setName($row['Label']); $schema->setNote($row['Note']); $schema->setStatusId(1); $schema->setToken($row['Name']); $schema->setUrl($row['URL']); $schema->save(); //todo: create a new import batch here and pass it to the import args //see importVocabulary->saveresults() //$batchId = //type $args[0] = "schema"; //filepath $args[1] = $GLOBALS['uploadPath'] . $row['File Name']; //vocabid $args[2] = $schema->getId(); $args[3] = $batchId; $args[4] = "-d"; run_import_vocabulary($importTask, $args); $foo = $schema->countSchemaPropertys(); } } catch(Exception $e) { throw new Exception($e); } } break; default: } }
/** * Retrieve multiple objects by pkey. * * @param array $pks List of primary keys * @param Connection $con the connection to use * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function retrieveByPKs($pks, $con = null) { if ($con === null) { $con = Propel::getConnection(self::DATABASE_NAME); } $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(); $criteria->add(SchemaPeer::ID, $pks, Criteria::IN); $objs = SchemaPeer::doSelect($criteria, $con); } return $objs; }