示例#1
0
 public function getTablePage($tableId)
 {
     $entity = new Schema();
     $entity->setName($tableId);
     $entity->setCollation("latin1_bin");
     $entity->setEngine(Engine::MYISAM());
     $entity->setType(Type::TABLE());
     return $entity;
 }
示例#2
0
文件: Schema.php 项目: helgi/Pyrus
 function find($tag)
 {
     foreach ($this->objs as $index => $obj) {
         if ($this->lastfind && $index != $this->lastfind) {
             continue;
         }
         if ($this->lastfind) {
             if ($obj->multiple() && $this->lastfind == $index) {
                 if ($test = $obj->findTag($tag)) {
                     return $test;
                 }
             }
             $this->lastfind = false;
             continue;
         }
         if ($obj->type === 'any') {
             if (($tag & 0x80) === 0x80) {
                 // context-sensitive tag, do best guess
                 if (($tag & 0x20) == 0x20) {
                     $tag = Sequence::TAG;
                 } else {
                     $tag = OctetString::TAG;
                 }
             }
             if (!isset($this->tagMap[$tag])) {
                 throw new Exception('Unknown tag: ' . dechex($tag) . ' at ' . $this->path());
             }
             $type = $this->tagMap[$tag];
             $ret = new Schema($this->parent, $tag, $type);
             $ret->setName($obj->name);
             $this->lastfind = $index;
             return $ret;
         }
         if ($test = $obj->findTag($tag)) {
             $this->lastfind = $index;
             if ($test->name != $index) {
                 $test = clone $test;
                 $test->setName($index);
             }
             return $test;
         }
         if (!$obj->optional()) {
             if (isset($this->tagMap[$tag])) {
                 $tag = '"' . str_replace('Pyrus\\DER\\', '', $this->tagMap[$tag]) . '" (0x' . dechex($tag) . ')';
             } else {
                 $tag = dechex($tag);
             }
             throw new Exception('Invalid DER document, required tag ' . $index . ' not found, instead requested ' . 'tag value ' . $tag . ' at ' . $this->path());
         }
     }
     if (isset($this->tagMap[$tag])) {
         $tag = '"' . str_replace('Pyrus\\DER\\', '', $this->tagMap[$tag]) . '" (0x' . dechex($tag) . ')';
     } else {
         $tag = dechex($tag);
     }
     throw new Exception('Invalid DER document, no matching elements for tag ' . $tag . ' at ' . $this->path());
 }
/**
 * 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:
    }
}
示例#4
0
 public function registerView($viewName)
 {
     $schemaPage = new Schema();
     $schemaPage->setName($name);
     $schemaPage->setType(Type::VIEW());
     $indexFile = $this->getSchemaIndexFile();
     $indexFile->addData($schemaPage->getData());
 }