/** * @return RokGallery_FileDeleteQueue */ public function &getInstance() { if (!isset(self::$_instance)) { self::$_instance = new RokGallery_Queue_DirectoryCreate(); } return self::$_instance; }
/** * @param Doctrine_Event $event */ public function postTransactionRollback(Doctrine_Event $event) { RokGallery_Queue_FileDelete::clear(); RokGallery_Queue_DirectoryDelete::clear(); RokGallery_Queue_FileCreate::process(); RokGallery_Queue_DirectoryCreate::process(); }
/** * Delete the file and all associated rows (done by foreign keys) and files * $params object should be a json like * <code> * { * 'id': 'xxxx-x-x-x-x-x-x' * } * </code> * * @param $params * @return RokCommon_Ajax_Result */ public function file($params) { $result = new RokCommon_Ajax_Result(); $tx = RokGallery_Doctrine::getConnection()->transaction; $tx->setIsolation('READ UNCOMMITTED'); try { if (count($_FILES) == 0) { throw new RokGallery_Job_Exception(rc__('ROKGALLERY_NO_FILES_SENT')); } $job = RokGallery_Job::get($params->id); if ($job === false) { throw new RokCommon_Ajax_Exception(rc__('ROKGALLERY_UNABLE_TO_FIND_JOB', $params->id)); } if ($job->getStateName() != RokGallery_Job::STATE_PREPPING) { throw new RokGallery_Job_Exception(rc__('ROKGALLERY_NOT_IN_PREPPING_STATUS')); } if ($job->getType() != RokGallery_Job::TYPE_IMPORT) { throw new RokGallery_Job_Exception(rc__('ROKGALLERY_NOT_AN_IMPORT_JOB')); } $job_properties = $job->getProperties(); if (empty($job_properties)) { $job_properties = array(); } $basepath = RokGallery_Config::getOption(RokGallery_Config::OPTION_JOB_QUEUE_PATH) . DS . $job->getId(); if (!file_exists($basepath)) { @mkdir($basepath); RokGallery_Queue_DirectoryCreate::add($basepath); } if (!(file_exists($basepath) && is_dir($basepath) && is_writable($basepath))) { throw new RokGallery_Job_Exception(rc__('ROKGALLERY_UNABLE_TO_CREATE_OR_WRITE_TO_TEMP_DIR', $basepath)); } $tx->beginTransaction(); foreach ($_FILES as $uploaded_file) { if ($uploaded_file['error'] == UPLOAD_ERR_OK) { $file = new RokGallery_Job_Property_ImportFile(); $file->setFilename($uploaded_file['name']); $file->setPath($basepath . DS . $file->getId()); move_uploaded_file($uploaded_file['tmp_name'], $file->getPath()); $job_properties[] = $file; } } $job->setProperties($job_properties); $job->save(); $tx->commit(); } catch (Exception $e) { $tx->rollback(); throw $e; } return $result; }
/** */ public function process() { try { /** @var RokGallery_Job_Property_ImportFile[] $import_files */ $import_files = $this->_job->getProperties(); $total_files = count($import_files); foreach ($import_files as $key => &$import_file) { $this->_job->refreshState(); if (!$this->_checkState($properties, 'Import')) { return; } if ($import_file->isCompleted()) { continue; } RokGallery_Doctrine::getConnection()->beginTransaction(); $file = RokGallery_Model_File::createNew($import_file->getFilename(), $import_file->getPath()); // If we need to check to make sure it is not a duplicated file if (RokGallery_Config::getOption(RokGallery_Config::OPTION_ALLOW_DUPLICATE_FILES, true) == false && RokGallery_Model_FileTable::getMD5($file->md5) !== false && RokGallery_Model_FileTable::getMD5($file->md5)->count() > 0) { throw new RokGallery_Job_Exception(rc__('ROKGALLERY_A_MATCHING_FILE_FOR_N_IN_SYSTEM', $file->filename)); } // Copy file to fine directory $basepath = dirname($file->getFullPath()); if (!file_exists($basepath)) { @mkdir($basepath, 0777, true); RokGallery_Queue_DirectoryCreate::add($basepath); } if (!(file_exists($basepath) && is_dir($basepath) && is_writable($basepath))) { throw new RokGallery_Job_Exception(rc__('ROKGALLERY_UNABLE_TO_CREATE_OR_WRITE_TO_THE_DIR_N', $basepath)); } // Move the file to its final location $endpath = $file->getFullPath(); rename($import_file->getPath(), $endpath); // update the image file info $file_image_info = @getimagesize($endpath); $file->xsize = $file_image_info[0]; /// x size $file->ysize = $file_image_info[1]; /// y size // Create the initial admin slice $this->createInitialAdminSlice($file); // Save the file to the db; $file->save(); $import_file->setCompleted(); $percent = (int) (($key + 1) / $total_files * 100); $this->_job->setProperties($import_files); $this->_job->save(rc__('ROKGALLERY_IMPORTED_FILE_N', $import_file->getFilename()), $percent); RokGallery_Doctrine::getConnection()->commit(); $file->free(true); } $this->_job->Complete('Importing Complete'); if (RokGallery_Config::getOption(RokGallery_Config::OPTION_AUTO_CLEAR_SUCCESSFUL_JOBS, false)) { sleep(5); $this->_job->Delete(); } return; } catch (Exception $e) { RokGallery_Doctrine::getConnection()->rollback(); $this->_job->Error($e->getMessage()); return; } }