/** * Injects a local file, which is a processing result into the object. * * @param string $filePath * @return void * @throws \RuntimeException */ public function updateWithLocalFile($filePath) { if ($this->identifier === null) { throw new \RuntimeException('Cannot update original file!', 1350582054); } $processingFolder = $this->originalFile->getStorage()->getProcessingFolder(); $addedFile = $this->storage->updateProcessedFile($filePath, $this, $processingFolder); // Update some related properties $this->identifier = $addedFile->getIdentifier(); $this->originalFileSha1 = $this->originalFile->getSha1(); $this->updateProperties($addedFile->getProperties()); $this->deleted = false; $this->updated = true; }
/** * Get an array of the width and height of the image file. * * @internal The process uses the saved constraints. It they are changed but * the derivative haven't been rebuilt, the return will be wrong (but * generally without consequences for BookReader). * * @param File $file * @param string $imageType * @return array Associative array of width and height of the image file. * If the file is not an image, the width and the height will be null. * @see UniversalViewer_View_Helper_IiifManifest::_getImageSize() */ protected function _getImageSize($file, $imageType = 'original') { static $sizeConstraints = array(); if (!isset($sizeConstraints[$imageType])) { $sizeConstraints[$imageType] = get_option($imageType . '_constraint'); } $sizeConstraint = $sizeConstraints[$imageType]; // Check if this is an image. if (empty($file) || strpos($file->mime_type, 'image/') !== 0) { $width = null; $height = null; } else { $metadata = json_decode($file->metadata, true); if (empty($metadata['video']['resolution_x']) || empty($metadata['video']['resolution_y'])) { $msg = __('The image #%d ("%s") is not stored correctly.', $file->id, $file->original_filename); _log($msg, Zend_Log::NOTICE); if (isset($metadata['video']['resolution_x']) || isset($metadata['video']['resolution_y'])) { throw new Exception($msg); } // Get the resolution directly. // The storage adapter should be checked for external storage. $storageAdapter = $file->getStorage()->getAdapter(); $filepath = get_class($storageAdapter) == 'Omeka_Storage_Adapter_Filesystem' ? FILES_DIR . DIRECTORY_SEPARATOR . $file->getStoragePath($imageType) : $file->getWebPath($imageType); list($width, $height, $type, $attr) = getimagesize($filepath); if (empty($width) || empty($height)) { throw new Exception($msg); } } else { $sourceWidth = $metadata['video']['resolution_x']; $sourceHeight = $metadata['video']['resolution_y']; // Use the original size when possible. if ($imageType == 'original') { $width = $sourceWidth; $height = $sourceHeight; } else { // Source is landscape. if ($sourceWidth > $sourceHeight) { $width = $sizeConstraint; $height = round($sourceHeight * $sizeConstraint / $sourceWidth); } elseif ($sourceWidth < $sourceHeight) { $width = round($sourceWidth * $sizeConstraint / $sourceHeight); $height = $sizeConstraint; } else { $width = $sizeConstraint; $height = $sizeConstraint; } } } } return array('width' => $width, 'height' => $height); }
/** * Get the storage the original file is located in * * @return ResourceStorage */ public function getStorage() { return $this->originalFile->getStorage(); }
/** * Constructor for a processed file object. Should normally not be used * directly, use the corresponding factory methods instead. * * @param File $originalFile * @param string $taskType * @param array $processingConfiguration * @param array $databaseRow */ public function __construct(File $originalFile, $taskType, array $processingConfiguration, array $databaseRow = NULL) { $this->originalFile = $originalFile; $this->storage = $originalFile->getStorage(); $this->taskType = $taskType; $this->processingConfiguration = $processingConfiguration; if (is_array($databaseRow)) { $this->reconstituteFromDatabaseRecord($databaseRow); } $this->taskTypeRegistry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\Processing\\TaskTypeRegistry'); }
/** * Performs the import task. */ public function perform() { // Set current user for this long running job. Zend_Registry::get('bootstrap')->bootstrap('Acl'); if ($this->_memoryLimit) { ini_set('memory_limit', $this->_memoryLimit); } $import = $this->_getImport(); if (empty($import)) { return; } $import->setBatchSize($this->_batchSize); try { call_user_func(array($import, $this->_method)); } catch (Zend_Http_Client_Exception $e) { $flagLoop = false; $msg = $e->getMessage(); // This check avoids an error when files are stored on Amazon S3. // Amazon S3 may stop the process randomly (about every 20 to 200 // files), when too many files are imported in one bucket. $file = new File(); $storage = $file->getStorage(); $adapter = $storage ? $storage->getAdapter() : null; if ($adapter && get_class($adapter) == 'Omeka_Storage_Adapter_ZendS3') { // Message used in Zend_Http_Client(), line 1085. if ($msg == 'Unable to read response, or response is empty') { $defaultValues = $import->getDefaultValues(); $s3Loop = isset($defaultValues['amazonS3CurrentLoop']) ? $defaultValues['amazonS3CurrentLoop'] : 0; $s3LoopMax = get_option('csv_import_repeat_amazon_s3'); $logMsg = __('The previous error is related to Amazon S3.'); if ($s3Loop < $s3LoopMax) { ++$s3Loop; $logMsg .= ' ' . __('CsvImport tries to relaunch the process #%d: %d/%d.', $this->_importId, $s3Loop, $s3LoopMax); $this->_log($logMsg, array(), Zend_Log::WARN); // The file position is not changed, so it will restart // from the row with the error. $defaultValues['amazonS3CurrentLoop'] = $s3Loop; $import->setDefaultValues($defaultValues); $import->status = CsvImport_Import::STATUS_QUEUED; $import->save(); $flagLoop = true; } else { $logMsg .= ' ' . __('CsvImport tried to relaunch the process #%d %d times without success.', $this->_importId, $s3LoopMax); $logMsg .= ' ' . __('Try to slow process and to increase the number of repetitions in the config page of CsvImport.'); $this->_log($logMsg, array(), Zend_Log::ERR); } } } if (!$flagLoop) { throw new Zend_Http_Client_Exception($msg); } } if ($import->isQueued() || $import->isQueuedUndo()) { $slowProcess = get_option('csv_import_slow_process'); if ($slowProcess) { sleep($slowProcess); } $this->_dispatcher->setQueueName(self::QUEUE_NAME); $this->_dispatcher->sendLongRunning(__CLASS__, array('importId' => $import->id, 'memoryLimit' => $this->_memoryLimit, 'method' => 'resume', 'batchSize' => $this->_batchSize)); } }