Exemplo n.º 1
0
 /**
  * Set defaults
  *
  * @param \FileImportHistory $file_import_history
  */
 public function setDefaults($file_import_history)
 {
     $schemaObj = $this->getCurrentSchema();
     $schemaId = $schemaObj->getId();
     if ('Vocabulary' == get_class($schemaObj)) {
         $file_import_history->setVocabularyId($schemaId);
     } else {
         $file_import_history->setSchemaId($schemaId);
     }
     $userId = sfContext::getInstance()->getUser()->getSubscriberId();
     $file_import_history->setUserId($userId);
     /** @var sfWebRequest $request */
     $request = $this->getRequest();
     if ($request->hasFile("file_import_history[filename]") and !$request->hasFileErrors()) {
         $sourceFile = $request->getFile("file_import_history[filename]");
         $file_import_history->setSourceFileName($sourceFile['name']);
         $file_import_history->setFileType($sourceFile['type']);
     }
     parent::setDefaults($file_import_history);
 }
Exemplo n.º 2
0
    public function saveResults($batchId = '')
    {
        $batchLog = new \BatchPeer();
        if ($batchId) {
            $criteria = new \Criteria();
            $criteria->add(\BatchPeer::ID, $batchId);
            /** @var $batch \Batch */
            $batch = $batchLog::doSelectOne($criteria);
        }

        if (empty( $batch )) {
            $batch = $batchLog->createBatchRecord(time(),
                                                  "manual import from file",
                                                  "schema",
                                                  "manual import (testing)",
                                                  "import",
                                                  $this->vocabId,
                                                  $this->vocabulary->getUri());
        }
        //there's a bunch more stuff we should save here
        $import = new \FileImportHistory();
        $import->setFileName($this->file);
        $import->setFileType($this->type);
        //todo $this->mapping isn't correct
        //$import->setMap($this->mapping);
        $import->setResults($this->results);
        $import->setUserId($this->userId);
        $import->setSchemaId($this->vocabId);
        $import->setBatch($batch);

        //$import->setBatch($batch);
        $import->save();

        return $batch->getId();
    }