コード例 #1
0
ファイル: Box.php プロジェクト: tomcbe/cbp-transcription-desk
    public function Insert(BoxEntity $oBoxEntity)
    {
        $sSql = 'INSERT INTO
					' . $this->sTableName . '
							(
							    job_queue_id
							  , box_number
							  , process
							  , process_status
							  , process_start_time
							  , updated
							)
				VALUES
							(
							    ?
							  , ?
							  , "import"
							  , "completed"
							  , NOW()
							  , NULL
							)
				 ON DUPLICATE KEY UPDATE
							id = LAST_INSERT_ID( id );';
        $aBindArray = array($oBoxEntity->getJobQueueId(), $oBoxEntity->getBoxNumber());
        $this->Execute($sSql, $aBindArray);
        $iBoxId = $this->oAdapter->getDriver()->getLastGeneratedValue();
        $oBoxEntity->setId($iBoxId);
        return $oBoxEntity;
    }
コード例 #2
0
 protected function ConstructPath(BoxEntity $oBoxEntity, FolioEntity $oFolioEntity, ItemEntity $oItemEntity)
 {
     $sBoxNumber = $oBoxEntity->getBoxNumber();
     $sFolioNumber = $oFolioEntity->getFolioNumber();
     $sItemNumber = $oItemEntity->getItemNumber();
     $sItemPath = $sBoxNumber . '/' . $sFolioNumber . '/' . $sItemNumber;
     return $sItemPath;
 }
コード例 #3
0
 private function ScanAndInsertFolioItems(BoxEntity $oBoxEntity, FolioEntity $oMappedFolioEntity)
 {
     $sBoxPrefix = $this->sBoxPrefix;
     $sBoxNumber = $oBoxEntity->getBoxNumber();
     $sFolioNumber = $oMappedFolioEntity->getFolioNumber();
     $aScannedItemNumbers = $this->aScannedFileNames[$sBoxNumber][$sFolioNumber];
     if ($aScannedItemNumbers < 1) {
         throw new ImporterException('ScanAndInsertFolioItems() could not find the meta data items: box number ' . $sBoxNumber . ' and folio number ' . $sFolioNumber . ' in the scanned files for box number ' . $sBoxPrefix . $sBoxNumber);
     }
     $oItemEntity = $this->oItemEntity;
     foreach ($aScannedItemNumbers as $sItemNumber) {
         $oItemEntity->SetAllPropertiesToNull();
         $oItemEntity->setItemNumber($sItemNumber);
         $iFolioId = $oMappedFolioEntity->getId();
         $oItemEntity->setFolioId($iFolioId);
         $oItemEntity = $this->oItemDb->Insert($oItemEntity);
         /* Already exists so updated and not inserted */
         $sItemUpdated = $oItemEntity->getUpdated();
         if ($sItemUpdated !== null) {
             $this->oLogger->Log('Item ' . $sItemNumber . ' already exists');
             continue;
         }
         $this->oLogger->Log('Inserted Item ' . $sItemNumber);
     }
     /* Remove the item from the array so reduce the size */
     unset($this->aScannedFileNames[$sBoxNumber][$sFolioNumber]);
     unset($this->aBoxFolioCollection[$sBoxNumber][$sFolioNumber]);
     // If we have reached this point then flag this folio as completed
     $this->oFolioDb->UpdateProcessStatus($iFolioId, 'import', 'completed');
     $this->oFolioDb->ClearErrorLog($iFolioId);
     $this->oLogger->Log('-----------------------------------');
 }
コード例 #4
0
 protected function ConstructPath(BoxEntity $oBoxEntity, FolioEntity $oFolioEntity, ItemEntity $oItemEntity)
 {
     $sBoxNumber = $oBoxEntity->getBoxNumber();
     $this->sBoxNumber = $sBoxNumber;
     $sFolioNumber = $oFolioEntity->getFolioNumber();
     $sItemNumber = $oItemEntity->getItemNumber();
     $sTokenSeperator = $this->sTokenSeperator;
     $sImagePath = $sBoxNumber . $sTokenSeperator . $sFolioNumber . $sTokenSeperator . $sItemNumber;
     return $sImagePath;
 }
コード例 #5
0
 protected function ProcessFolios(BoxEntity $oBoxEntity)
 {
     $iBoxId = $oBoxEntity->getId();
     $rFolios = $this->GetFolios($iBoxId);
     if ($rFolios->count() < 1) {
         $this->oLogger->Log('ProcessFolios(): No folios could be found with ' . $this->sPreviousProcess . ' completed');
         return;
     }
     /* @var $oFolioEntity FolioEntity */
     while ($oFolioEntity = $rFolios->getResource()->fetchObject('Classes\\Entities\\Folio')) {
         $iFolioId = $oFolioEntity->getId();
         $this->oFolioDb->UpdateProcessStatus($iFolioId, $this->sProcess, 'started');
         $this->oFolioDb->ClearErrorLog($iFolioId);
         try {
             $this->ProcessItems($oBoxEntity, $oFolioEntity);
         } catch (ImporterException $oException) {
             $this->HandleError($oException, $oFolioEntity);
         }
         $this->oFolioDb->UpdateProcessStatus($iFolioId, $this->sProcess, 'completed');
     }
 }
コード例 #6
0
 protected function ConstructPath(BoxEntity $oBoxEntity, FolioEntity $oFolioEntity, ItemEntity $oItemEntity)
 {
     $sBoxNumber = $oBoxEntity->getBoxNumber();
     $sFolioNumber = $oFolioEntity->getFolioNumber();
     $sItemNumber = $oItemEntity->getItemNumber();
     $sBoxPrefix = $this->sBoxPrefix;
     $sImageExportPath = $this->sImageExportPath;
     $sImageImportPath = $this->sImageImportPath;
     $sJobArchivePath = $this->sArchivePath;
     $sTokenSeperator = $this->sTokenSeperator;
     $iJobQueueId = $this->iJobQueueId;
     // Check whether slices already exixt
     $sImagePath = $sBoxNumber . DIRECTORY_SEPARATOR . $sBoxNumber . $sTokenSeperator . $sFolioNumber . $sTokenSeperator . $sItemNumber;
     // Check to see whether images have already been processes
     $sImageExportPath = $this->sImageExportPath;
     $sTargetPath = $sImageExportPath . DIRECTORY_SEPARATOR . $sImagePath;
     $bTargetPathExists = file_exists($sTargetPath);
     if ($bTargetPathExists) {
         $this->oLogger->Log($sTargetPath . ' already exists. Skipping...');
         return '';
     }
     // They have not been processed so carry on and determine the images full path
     $sImageImportPath = $this->sImageImportPath;
     $this->oFile->CheckDirExists($sImageImportPath);
     $sBoxPrefix = $this->sBoxPrefix;
     $sItemName = DIRECTORY_SEPARATOR . $sBoxPrefix . $sImagePath . '.jpg';
     $sFullImageImportPath = $sImageImportPath . $sItemName;
     // Fall back to Archive directory if needed
     if (file_exists($sFullImageImportPath) === false) {
         $sFullImageArchivePath = $sJobArchivePath . DIRECTORY_SEPARATOR . $iJobQueueId . $sItemName;
         $this->oLogger->Log($sFullImageImportPath . ' no longer exists. Now checking archive ' . $sFullImageArchivePath);
         if (file_exists($sFullImageArchivePath)) {
             //Before we move file, create the parent BOX directory otherwise it will complain
             $sTargetImageDirectory = $this->sImageImportPath . DIRECTORY_SEPARATOR . $sBoxPrefix . $sBoxNumber;
             if (!is_dir($sTargetImageDirectory)) {
                 if (!mkdir($sTargetImageDirectory, 0775, true)) {
                     throw new ImporterException('ConstructPath(): Failed to create ' . $sTargetImageDirectory);
                 }
                 $this->oLogger->Log('Created directory ' . $sTargetImageDirectory);
             }
             $this->oLogger->Log('Moving archived image back from ' . $sFullImageArchivePath . ' to ' . $sFullImageImportPath);
             if (!rename($sFullImageArchivePath, $sFullImageImportPath)) {
                 throw new ImporterException('ConstructPath(): unable to rename ' . $sFullImageArchivePath . ' to ' . $sFullImageImportPath);
             }
         }
         // Otherwise move it back from the archive
     }
     // Do one last check
     $bDirExists = file_exists($sFullImageImportPath);
     // If it doesn't exist in the Archive directory there then we have a genuine problem so throw an exception
     if ($bDirExists === false) {
         throw new ImporterException('FullImageImportPath ' . $sFullImageImportPath . ' does not exist');
     }
     return $sFullImageImportPath;
 }