/** * Deletes an existing upload file. * For images the thumbnails are removed, too. * * @param string $objectType Currently treated entity type. * @param string $objectData Object data array. * @param string $fieldName Name of upload field. * @param integer $objectId Primary identifier of the given object. * * @return mixed Array with updated object data on success, else false. */ public function deleteUploadFile($objectType, $objectData, $fieldName, $objectId) { if (!in_array($objectType, $this->allowedObjectTypes)) { return false; } if (empty($objectData[$fieldName])) { return $objectData; } $serviceManager = ServiceUtil::getManager(); $controllerHelper = new Reviews_Util_Controller($serviceManager); // determine file system information try { $basePath = $controllerHelper->getFileBaseFolder($objectType, $fieldName); } catch (\Exception $e) { LogUtil::registerError($e->getMessage()); return $objectData; } $fileName = $objectData[$fieldName]; // path to original file $filePath = $basePath . $fileName; // check whether we have to consider thumbnails, too $fileExtension = FileUtil::getExtension($fileName, false); if (in_array($fileExtension, $this->imageFileTypes) && $fileExtension != 'swf') { // remove thumbnail images as well $manager = ServiceUtil::getManager()->getService('systemplugin.imagine.manager'); $manager->setModule('Reviews'); $fullObjectId = $objectType . '-' . $objectId; $manager->removeImageThumbs($filePath, $fullObjectId); } // remove original file if (!unlink($filePath)) { return false; } $objectData[$fieldName] = ''; $objectData[$fieldName . 'Meta'] = array(); return $objectData; }
/** * Post-Process the data after the entity has been constructed by the entity manager. * The event happens after the entity has been loaded from database or after a refresh call. * * Restrictions: * - no access to entity manager or unit of work apis * - no access to associations (not initialised yet) * * @see Reviews_Entity_Review::postLoadCallback() * @return boolean true if completed successfully else false. */ protected function performPostLoadCallback() { // echo 'loaded a record ...'; $currentFunc = FormUtil::getPassedValue('func', 'main', 'GETPOST', FILTER_SANITIZE_STRING); $usesCsvOutput = FormUtil::getPassedValue('usecsvext', false, 'GETPOST', FILTER_SANITIZE_STRING); // initialise the upload handler $uploadManager = new Reviews_UploadHandler(); $serviceManager = ServiceUtil::getManager(); $controllerHelper = new Reviews_Util_Controller($serviceManager); $this['id'] = (int) (isset($this['id']) && !empty($this['id']) ? DataUtil::formatForDisplay($this['id']) : 0); $this->formatTextualField('workflowState', $currentFunc, $usesCsvOutput, true); $this->formatTextualField('title', $currentFunc, $usesCsvOutput); $this->formatTextualField('text', $currentFunc, $usesCsvOutput); $this->formatTextualField('zlanguage', $currentFunc, $usesCsvOutput); $this->formatTextualField('reviewer', $currentFunc, $usesCsvOutput); $this->formatTextualField('email', $currentFunc, $usesCsvOutput); $this->formatTextualField('score', $currentFunc, $usesCsvOutput, true); $this['url'] = isset($this['url']) && !empty($this['url']) ? DataUtil::formatForDisplay($this['url']) : ''; $this->formatTextualField('url_title', $currentFunc, $usesCsvOutput); $this['hits'] = (int) (isset($this['hits']) && !empty($this['hits']) ? DataUtil::formatForDisplay($this['hits']) : 0); $this->formatTextualField('cover', $currentFunc, $usesCsvOutput); if (!empty($this['coverUpload'])) { try { $basePath = $controllerHelper->getFileBaseFolder('review', 'coverUpload'); } catch (\Exception $e) { return LogUtil::registerError($e->getMessage()); } $fullPath = $basePath . $this['coverUpload']; $this['coverUploadFullPath'] = $fullPath; $this['coverUploadFullPathURL'] = System::getBaseUrl() . $fullPath; // just some backwards compatibility stuff /*if (!isset($this['coverUploadMeta']) || !is_array($this['coverUploadMeta']) || !count($this['coverUploadMeta'])) { // assign new meta data $this['coverUploadMeta'] = $uploadManager->readMetaDataForFile($this['coverUpload'], $fullPath); }*/ } $this->prepareItemActions(); return true; }