/** * @return AM_Handler_Locator */ public static function getInstance() { if (is_null(self::$_oInstance)) { self::$_oInstance = new self(); } return self::$_oInstance; }
public function execute() { $iIdRevision = intval($this->_getOption('revision')); $iIdFrom = intval($this->_getOption('from')); //If this option is set, we are building packaged for issues with id > $iIdFrom $iIssueId = intval($this->_getOption('issue')); $iApplicationId = intval($this->_getOption('application')); $oQuery = AM_Model_Db_Table_Abstract::factory('term')->select()->setIntegrityCheck(false)->from('revision')->joinInner('issue', 'issue.id = revision.issue')->joinInner('application', 'application.id = issue.application')->joinInner('client', 'client.id = application.client')->where('revision.deleted = ?', 'no')->where('issue.deleted = ?', 'no')->where('application.deleted = ?', 'no')->where('client.deleted = ?', 'no')->columns(array('id' => 'revision.id'))->order('revision.id ASC'); if ($iIdFrom > 0) { $oQuery->where('revision.id > ?', $iIdFrom); } if ($iIdRevision > 0) { $oQuery->where('revision.id = ?', $iIdRevision); } if ($iIssueId > 0) { $oQuery->where('issue.id = ?', $iIssueId); } if ($iApplicationId > 0) { $oQuery->where('application.id = ?', $iApplicationId); } $oRevisions = AM_Model_Db_Table_Abstract::factory('revision')->fetchAll($oQuery); $oExportHandler = AM_Handler_Locator::getInstance()->getHandler('export'); /* @var $oExportHandler AM_Handler_Export */ foreach ($oRevisions as $oRevision) { $oExportHandler->exportRevision($oRevision); } }
public function setUp() { $this->oStandardMock = $this->getMock('AM_Tools_Standard', array('is_file', 'mkdir', 'copy', 'chmod')); $oThumbnailHandler = AM_Handler_Locator::getInstance()->getHandler('thumbnail'); $aConfig = array('thumbnailFolder' => self::THUMBNAIL_FOLDER, 'thumbnailFileChmod' => self::THUMBNAIL_FILE_CHMOD, 'thumbnailDirChmod' => self::THUMBNAIL_DIR_CHMOD); $this->oStorage = new AM_Handler_Thumbnail_Storage_Local($oThumbnailHandler, new Zend_Config($aConfig)); $this->oStorage->setPathPrefix(self::PATH_PREFIX); }
/** * Defined by Zend_Application_Resource_Resource * * @return AM_Handler_Locator */ public function init() { $oHandlerLocator = AM_Handler_Locator::getInstance(); $aOptions = $this->getOptions(); foreach ($aOptions as $sHandlerName => $sHandlerClass) { $oHandlerLocator->setHandler($sHandlerName, $sHandlerClass); } return $oHandlerLocator; }
public function setUp() { parent::setUp(); $this->_oStaticPdf = AM_Model_Db_Table_Abstract::factory('static_pdf')->findOneBy(array('id' => 1)); $this->_oStandardMock = $this->getMock('AM_Tools_Standard', array('is_dir', 'mkdir')); $this->_oUploaderMock = $this->getMock('AM_Handler_Upload', array('isValid', 'isUploaded', 'getFileInfo', 'receive')); $this->_oThumbnailerMock = $this->getMock('AM_Handler_Thumbnail', array('addSourceFile', 'loadAllPresets', 'createThumbnails', 'getSources')); AM_Handler_Locator::getInstance()->setHandler('thumbnail', $this->_oThumbnailerMock); }
/** * @see AM_Task_Worker_Abstract::_fire() * @throws AM_Task_Worker_Exception * @return void */ protected function _fire() { $oThumbnailer = AM_Handler_Locator::getInstance()->getHandler('thumbnail'); $sResource = (string) $this->getOption('resource'); $aImageType = (string) $this->getOption('image_type'); $bZooming = (bool) $this->getOption('zooming'); $sResourceType = (string) $this->getOption('resource_type'); $oThumbnailer->clearSources()->addSourceFile($sResource)->setImageType($aImageType)->loadAllPresets($sResourceType, false)->setZooming($bZooming)->createThumbnails(); }
public function execute() { $this->_iFromId = intval($this->_getOption('from')); $this->_iRevisionId = intval($this->_getOption('revision')); $this->_iIssueId = intval($this->_getOption('issue')); $this->_iApplicationId = intval($this->_getOption('application')); $this->_oThumbnailer = AM_Handler_Locator::getInstance()->getHandler('thumbnail'); $this->_echo('Resizing TOC'); $this->_resizeTOC(); }
public function execute() { $this->_iFromIssueId = intval($this->_getOption('from')); $this->_iIssueId = intval($this->_getOption('issue')); $this->_iApplicationId = intval($this->_getOption('application')); $this->_sPreset = (string) $this->_getOption('preset'); $this->_oThumbnailer = AM_Handler_Locator::getInstance()->getHandler('thumbnail'); $this->_echo('Resizing horizontal pages'); $this->_resizeHorizontalPdfs(); }
/** * @see AM_Task_Worker_Abstract::_fire() * @throws AM_Task_Worker_Exception * @return void */ protected function _fire() { $iIssueId = intval($this->getOption('issue_id')); $oIssue = AM_Model_Db_Table_Abstract::factory('issue')->findOneBy(array('id' => $iIssueId)); if (is_null($oIssue)) { throw new AM_Task_Worker_Exception(sprintf('Issue with id "%d" not found'), $iIssueId); } $oHorizontalPdfHandler = AM_Handler_Locator::getInstance()->getHandler('horisontal_pdf'); /* @var $oHorizontalPdfHandler AM_Handler_HorisontalPdf */ $oHorizontalPdfHandler->setIssue($oIssue)->compile(); }
public function execute() { $this->_iFromId = intval($this->_getOption('from')); $this->_iElementId = intval($this->_getOption('element')); $this->_iRevisionId = intval($this->_getOption('revision')); $this->_iPageId = intval($this->_getOption('page')); $this->_iIssueId = intval($this->_getOption('issue')); $this->_iApplicationId = intval($this->_getOption('application')); $this->_sPreset = (string) $this->_getOption('preset'); $this->_oThumbnailer = AM_Handler_Locator::getInstance()->getHandler('thumbnail'); $this->_echo('Resizing elements'); $this->_resizeElements(); }
public function testShouldCopyResource() { //GIVEN $oThumbnailerMock = $this->getMock('AM_Handler_Thumbnail', array('addSourceFile', 'loadAllPresets', 'createThumbnails', 'getSources')); AM_Handler_Locator::getInstance()->setHandler('thumbnail', $oThumbnailerMock); $oStandardMock = $this->getMock('AM_Tools_Standard', array('is_dir', 'mkdir', 'copy')); $oElement = AM_Model_Db_Table_Abstract::factory('element')->findOneBy('id', 1); $oResource = new AM_Model_Db_Element_Data_MockResource($oElement); $oResource->addAdditionalResourceKey('additional_key'); //Emulating the element copying $oElement->id = 2; //The current path of the resource $sOldDir = AM_Tools::getContentPath(AM_Model_Db_Element_Data_Resource::TYPE, 1); //The path of the resource after copying $sNewDir = AM_Tools::getContentPath(AM_Model_Db_Element_Data_Resource::TYPE, 2); //THEN //Checking all file operations $oStandardMock->expects($this->at(0))->method('is_dir')->with($this->equalTo($sOldDir))->will($this->returnValue(true)); $oStandardMock->expects($this->at(1))->method('is_dir')->with($this->equalTo($sNewDir))->will($this->returnValue(false)); $oStandardMock->expects($this->once())->method('mkdir')->with($this->equalTo($sNewDir), $this->equalTo(0777), $this->equalTo(true))->will($this->returnValue(true)); $sNewResourcePath = $sNewDir . DIRECTORY_SEPARATOR . 'resource.png'; $sOldResourcePath = $sOldDir . DIRECTORY_SEPARATOR . 'resource.png'; $sNewAdditionalResourcePath = $sNewDir . DIRECTORY_SEPARATOR . 'additional_key.png'; $sOldAdditionalResourcePath = $sOldDir . DIRECTORY_SEPARATOR . 'additional_key.png'; $oStandardMock->expects($this->at(3))->method('copy')->with($this->equalTo($sOldResourcePath), $this->equalTo($sNewResourcePath))->will($this->returnValue(true)); $oStandardMock->expects($this->at(4))->method('copy')->with($this->equalTo($sOldAdditionalResourcePath), $this->equalTo($sNewAdditionalResourcePath))->will($this->returnValue(true)); //Checking the init of the resizing operation $oThumbnailerMock->expects($this->any())->method('addSourceFile')->will($this->returnValue($oThumbnailerMock)); $oThumbnailerMock->expects($this->any())->method('loadAllPresets')->will($this->returnValue($oThumbnailerMock)); $oResourceMock = new AM_Resource_Concrete_Mock($sNewResourcePath); $oThumbnailerMock->expects($this->at(3))->method('getSources')->will($this->returnValue(array($oResourceMock))); $oAdditionalResourceMock = new AM_Resource_Concrete_Mock($sNewAdditionalResourcePath); $oThumbnailerMock->expects($this->at(7))->method('getSources')->will($this->returnValue(array($oAdditionalResourceMock))); //WHEN $oResource->copy(); //THEN $oGivenDataSet = $this->getConnection()->createQueryTable('element_data', 'SELECT id_element, key_name, value FROM element_data ORDER BY id'); $oExpectedDataSet = $this->createFlatXMLDataSet(dirname(__FILE__) . '/_dataset/ElementResourceCopyTest.xml')->getTable('element_data'); $this->assertTablesEqual($oExpectedDataSet, $oGivenDataSet); //Checking the background tasks $oTasks = AM_Model_Db_Table_Abstract::factory('task')->findAllBy(array('status' => AM_Task_Worker_Abstract::STATUS_NEW)); $this->assertEquals(2, $oTasks->count(), 'Precess should init 2 tasks'); $oTaskForResource = $oTasks[0]; $aExpectedParams = array('resource' => $sNewResourcePath, 'image_type' => 'png', 'zooming' => 0, 'resource_type' => 'element-vertical'); $this->assertEquals($aExpectedParams, $oTaskForResource->getOptions()); $oTaskForAdditionalResource = $oTasks[1]; $aExpectedParams = array('resource' => $sNewAdditionalResourcePath, 'image_type' => 'png', 'zooming' => 0, 'resource_type' => 'element-vertical'); $this->assertEquals($aExpectedParams, $oTaskForAdditionalResource->getOptions()); }
/** * Defined by Zend_Application_Resource_Resource * * @return AM_Handler_Thumbnail_Storage_Abstract */ public function init() { $this->getBootstrap()->bootstrap('handlermanager'); $aOptions = $this->getOptions(); $sAdapter = $aOptions['adapter']; $sAdapterClassName = self::CLASS_PREFIX . '_' . ucfirst($sAdapter); $sFile = str_replace('_', DIRECTORY_SEPARATOR, $sAdapterClassName) . '.php'; if (!AM_Tools_Standard::getInstance()->isReadable($sFile)) { throw new AM_Exception(sprintf('Adapter class \'%s\' not found', $sAdapterClassName), 502); } $oThumbnailHandler = AM_Handler_Locator::getInstance()->getHandler('thumbnail'); $oStorage = new $sAdapterClassName($oThumbnailHandler, new Zend_Config($aOptions['options'])); if (!$oStorage instanceof AM_Handler_Thumbnail_Storage_Abstract) { throw new AM_Exception(sprintf('Wrong resource storage given', 501)); } return $oStorage; }
/** * Export revision action * * Sends revision package */ public function revisionAction() { try { $message['status'] = 0; $iRevisionId = intval($this->_getParam('id')); $mIsContinue = $this->_getParam('continue'); $oRevision = AM_Model_Db_Table_Abstract::factory('revision')->findOneBy('id', $iRevisionId); /* @var $oRevision AM_Model_Db_Revision */ if (is_null($oRevision)) { throw new AM_Controller_Exception_BadRequest(sprintf('Revision "%s" not found', $iRevisionId)); } $oHandler = AM_Handler_Locator::getInstance()->getHandler('export'); /* @var $oHandler AM_Handler_Export */ $oHandler->sendRevisionPackage($oRevision, $mIsContinue); } catch (Exception $e) { $this->getResponse()->setHttpResponseCode(500)->setBody('Error. Internal Server Error. ' . $e->getMessage())->sendResponse(); } exit; }
public function move($recordKeyValue = null) { if (!$this->value || $this->bPreventFileMoving) { return true; } $fileFolder = str_replace("[ID]", trim(AM_Tools_String::generatePathFromId($recordKeyValue), DIRECTORY_SEPARATOR), $this->fileFolder); if (!@is_dir($fileFolder)) { if (!@mkdir($fileFolder, Volcano_Component_Control_Database_File::$folderMode, true)) { $this->errors[] = $this->localizer->translate("File I/O Error"); return false; } } $sDestination = $fileFolder . "/" . $this->value; if (!@move_uploaded_file($_FILES[$this->name]["tmp_name"], $sDestination)) { $this->errors[] = $this->localizer->translate("File I/O Error"); return false; } $oThumbnailerHandler = AM_Handler_Locator::getInstance()->getHandler('thumbnail'); /* @var $oThumbnailerHandler AM_Handler_Thumbnail */ $oThumbnailerHandler->clearSources()->addSourceFile($sDestination)->loadAllPresets(AM_Model_Db_Issue::PRESET_ISSUE_IMAGE)->createThumbnails(); return true; }
/** * Compile static pdf * @return AM_Handler_HorisontalPdf * @throws AM_Handler_HorisontalPdf_Exception */ public function compile() { AM_Model_Db_Table_Abstract::factory('page')->resetHorizontalPdf($this->getIssue()); AM_Model_Db_Table_Abstract::factory('page_horisontal')->deleteBy(array('id_issue' => $this->getIssue()->id)); AM_Tools::clearContent(AM_Model_Db_StaticPdf_Data_Abstract::TYPE_CACHE, $this->getIssue()->id); AM_Tools::clearResizerCache(AM_Model_Db_StaticPdf_Data_Abstract::TYPE_CACHE, AM_Model_Db_StaticPdf_Data_Abstract::TYPE_CACHE, $this->getIssue()->id); if (!count($this->getIssue()->getHorizontalPdfs())) { return $this; } switch ($this->getIssue()->static_pdf_mode) { case AM_Model_Db_Issue::HORISONTAL_MODE_PAGE: //Get first pages of all pdfs and glue them $aFiles = (array) $this->_compilePageVersion(); break; case AM_Model_Db_Issue::HORISONTAL_MODE_ISSUE: //Get pdf's first pages and glue them $aFiles = (array) $this->_compileIssueVersion(); break; case AM_Model_Db_Issue::HORISONTAL_MODE_2PAGES: //Get all pdf's pages and glue them $aFiles = (array) $this->_compile2PagesVersion(); break; } $sCachePath = $this->_getFilesPath(); if (!empty($aFiles)) { if (!AM_Tools_Standard::getInstance()->is_dir($sCachePath)) { if (!AM_Tools_Standard::getInstance()->mkdir($sCachePath, 0777, true)) { throw new AM_Handler_HorisontalPdf_Exception('I/O error while create cache dir'); } } $oThumbnailer = AM_Handler_Locator::getInstance()->getHandler('thumbnail'); /* @var $oThumbnailer AM_Handler_Thumbnail */ $oThumbnailer->clearSources()->loadAllPresets(AM_Model_Db_StaticPdf_Data_Abstract::TYPE_CACHE)->setImageType(AM_Handler_Thumbnail::IMAGE_TYPE_JPEG); foreach ($aFiles as $sFile) { $sFilename = pathinfo($sFile, PATHINFO_BASENAME); $sNewFilePath = $sCachePath . DIRECTORY_SEPARATOR . $sFilename; if (!AM_Tools_Standard::getInstance()->rename($sFile, $sNewFilePath)) { throw new AM_Handler_HorisontalPdf_Exception('I/O error while copy file'); } AM_Tools_Standard::getInstance()->chmod($sNewFilePath, 0666); if (AM_Tools::isAllowedImageExtension($sNewFilePath)) { $oThumbnailer->addSourceFile($sNewFilePath); } $oPageHorisontal = new AM_Model_Db_PageHorisontal(); $oPageHorisontal->id_issue = $this->getIssue()->id; $oPageHorisontal->resource = $sFilename; $oPageHorisontal->weight = pathinfo($sFile, PATHINFO_FILENAME); $oPageHorisontal->save(); } $oThumbnailer->createThumbnails(); } return $this; }
/** * Post upload trigger * @param type $sDestination * @return AM_Model_Db_Term_Data_Resource */ protected function _postUpload($sDestination) { if (AM_Tools::isAllowedImageExtension($sDestination)) { $oThumbnailerHandler = AM_Handler_Locator::getInstance()->getHandler('thumbnail'); /* @var $oThumbnailerHandler AM_Handler_Thumbnail */ $oThumbnailerHandler->clearSources()->setImageType($this->getImageType())->addSourceFile($sDestination)->loadAllPresets(self::TYPE)->createThumbnails(); } return $this; }
public function setUp() { //GIVEN $this->oLocator = AM_Handler_Locator::getInstance(); }
/** * Returns horizontal versions archive * @return string */ public function getHorizontalPdfsArchive() { $oHorizontalPdfHandler = AM_Handler_Locator::getInstance()->getHandler('horisontal_pdf'); /* @var $oHorizontalPdfHandler AM_Handler_HorisontalPdf */ $oHorizontalPdfHandler->setIssue($this); $sFilePath = $oHorizontalPdfHandler->getArchive(); return $sFilePath; }
/** * @todo refactoring. We have to get page background by field weight * @param boolean $bUpdateBackground * @return void */ public function setUpdated($bUpdateBackground = true) { $oExportHandler = AM_Handler_Locator::getInstance()->getHandler('export'); /* @var $handler AM_Handler_Export */ $this->updated = new Zend_Db_Expr('NOW()'); $this->save(); $this->getRevision()->updated = new Zend_Db_Expr('NOW()'); $this->getRevision()->save(); $this->getIssue()->updated = new Zend_Db_Expr('NOW()'); $this->getIssue()->save(); if (!$bUpdateBackground) { $oExportHandler->initExportProcess($this->getRevision()); return; } $oNotSortedFields = $this->getFields(); $aFields = array(); foreach ($oNotSortedFields as $oField) { if (!isset(self::$aBackgroundPriority[$oField->getFieldType()->title])) { continue; } $aFields[self::$aBackgroundPriority[$oField->getFieldType()->title]] = $oField; } ksort($aFields); $oField = null; $oElement = null; $sFileName = null; foreach ($aFields as $oFieldItem) { $oElements = $this->getElementsByField($oFieldItem); if (!count($oElements)) { continue; } foreach ($oElements as $elementsItem) { /* @var $elementsItem AM_Model_Db_Element */ $sFileName = $elementsItem->getResources()->getDataValue(AM_Model_Db_Element_Data_Resource::DATA_KEY_RESOURCE); if (!$sFileName) { continue; } $oField = $oFieldItem; $oElement = $elementsItem; break; } if ($oElement && $oField) { break; } } if (is_null($oField) || is_null($oElement)) { AM_Model_Db_Table_Abstract::factory('page_background')->deleteBy(array('page' => $this->id)); $oExportHandler->initExportProcess($this->getRevision()); return; } $oBackground = $this->getPageBackground(); if (!is_null($oBackground)) { $oBackground->id = $oElement->id; $oBackground->filename = AM_Model_Db_Element_Data_Resource::DATA_KEY_RESOURCE . '.' . pathinfo($sFileName, PATHINFO_EXTENSION); $oBackground->updated = $oElement->updated; $oBackground->setElement($oElement); } else { $oBackground = new AM_Model_Db_PageBackground(); $oBackground->id = $oElement->id; $oBackground->filename = AM_Model_Db_Element_Data_Resource::DATA_KEY_RESOURCE . '.' . pathinfo($sFileName, PATHINFO_EXTENSION); $oBackground->updated = $oElement->updated; $oBackground->page = $this->id; $oBackground->type = 'element'; $oBackground->setElement($oElement); } $oBackground->save(); $oExportHandler->initExportProcess($this->getRevision()); return; }
/** * Post upload trigger * @param string $sDestination The path to file that has been uploaded * @param string $sKey * @return AM_Model_Db_Element_Data_Resource */ protected function _postUpload($sDestination, $sKey = null) { $oThumbnailer = AM_Handler_Locator::getInstance()->getHandler('thumbnail'); /* @var $oThumbnailer AM_Handler_Thumbnail */ $oThumbnailer->clearSources()->addSourceFile($sDestination)->setImageType($this->getImageType($sKey))->loadAllPresets($this->getThumbnailPresetName(), true)->createThumbnails(); foreach ($oThumbnailer->getSources() as $oSource) { if ($oSource->isImage()) { $oTask = new AM_Task_Worker_Thumbnail_Create(); $oTask->setOptions(array('resource' => $sDestination, 'image_type' => $this->getImageType($sKey), 'zooming' => false, 'resource_type' => $this->getThumbnailPresetName()))->create(); } if ($oSource->isPdf() && self::DATA_KEY_RESOURCE == $sKey) { //Remove old pdf_info $this->delete(self::PDF_INFO, false); $sPdfInfo = $oSource->getPdfInfo(); $this->addKeyValue(self::PDF_INFO, $sPdfInfo); return $this; } } return $this; }
protected function _configure() { $this->addOption('issue', 'i', '=i', 'Issue ID'); AM_Handler_Locator::getInstance()->setHandler('horisontal_pdf', 'AM_Handler_HorisontalPdf'); }
/** * Init export process for revision * @return AM_Model_Db_Revision */ public function exportRevision() { $oExportHandler = AM_Handler_Locator::getInstance()->getHandler('export'); /* @var $oExportHandler AM_Handler_Export */ $oExportHandler->initExportProcess($this); return $this; }
/** * Get resolutions list * * @return array * @throws AM_Api_Client_Exception */ public function getResolutions() { $mResponse = array(); $oThumbnailer = AM_Handler_Locator::getInstance()->getHandler('thumbnail'); /* @var $oThumbnailer AM_Handler_Thumbnail */ $mResponse['page-horizontal'] = $oThumbnailer->getResolutions(AM_Model_Db_StaticPdf_Data_Abstract::TYPE_CACHE); $mResponse['menu'] = $oThumbnailer->getResolutions(AM_Model_Db_Term_Data_Abstract::TYPE); $mResponse['element-vertical'] = $oThumbnailer->getResolutions(AM_Model_Db_Element_Data_Abstract::TYPE . '-vertical'); $mResponse['element-horizontal'] = $oThumbnailer->getResolutions(AM_Model_Db_Element_Data_Abstract::TYPE . '-horizontal'); $mResponse['help-page-vertical'] = $oThumbnailer->getResolutions(AM_Model_Db_IssueHelpPage_Data_Abstract::TYPE . '-vertical'); $mResponse['help-page-horizontal'] = $oThumbnailer->getResolutions(AM_Model_Db_IssueHelpPage_Data_Abstract::TYPE . '-horizontal'); return $mResponse; }
/** * Post upload trigger * @param string $sDestination * @return AM_Model_Db_IssueHelpPage_Data_Resource */ protected function _postUpload($sDestination) { if (AM_Tools::isAllowedImageExtension($sDestination)) { $oThumbnailerHandler = AM_Handler_Locator::getInstance()->getHandler('thumbnail'); /* @var $oThumbnailerHandler AM_Handler_Thumbnail */ $oThumbnailerHandler->clearSources()->addSourceFile($sDestination)->setImageType($this->getImageType())->loadAllPresets($this->_getIssueHelpPage()->getThumbnailPresetType(), true)->createThumbnails(); $oTask = new AM_Task_Worker_Thumbnail_Create(); $oTask->setOptions(array('resource' => $sDestination, 'image_type' => $this->getImageType(), 'zooming' => false, 'resource_type' => $this->_getIssueHelpPage()->getThumbnailPresetType()))->create(); } return $this; }
protected function tearDown() { parent::tearDown(); AM_Handler_Locator::getInstance()->setHandler('thumbnail', 'AM_Handler_Thumbnail'); }
/** * Returns path to the resized resource * * @todo Refactor and move to the separate helper * @param string $sPreset The name of resizing preset * @param string $sType The type of resource (element, toc, static-pdf, etc.) * @param int $iId * @param string $sFileName * @return string */ public static function getImageUrl($sPreset, $sType, $iId = null, $sFileName = null, $sFileExtension = null) { $oThumbnailerHandler = AM_Handler_Locator::getInstance()->getHandler('thumbnail'); /* @var $oThumbnailerHandler AM_Handler_Thumbnail */ $sImageUrl = $oThumbnailerHandler->getResourceUrl($sPreset, $sType, $iId, $sFileName, $sFileExtension); return $sImageUrl; }