/** * 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 MUVideo_Entity_Movie::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_VALIDATE_BOOLEAN); // initialise the upload handler $uploadManager = new MUVideo_UploadHandler(); $serviceManager = ServiceUtil::getManager(); $controllerHelper = new MUVideo_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('description', $currentFunc, $usesCsvOutput); if (!empty($this['uploadOfMovie'])) { try { $basePath = $controllerHelper->getFileBaseFolder('movie', 'uploadOfMovie'); } catch (\Exception $e) { return LogUtil::registerError($e->getMessage()); } $fullPath = $basePath . $this['uploadOfMovie']; $this['uploadOfMovieFullPath'] = $fullPath; $this['uploadOfMovieFullPathURL'] = System::getBaseUrl() . $fullPath; // just some backwards compatibility stuff /*if (!isset($this['uploadOfMovieMeta']) || !is_array($this['uploadOfMovieMeta']) || !count($this['uploadOfMovieMeta'])) { // assign new meta data $this['uploadOfMovieMeta'] = $uploadManager->readMetaDataForFile($this['uploadOfMovie'], $fullPath); }*/ } $this['urlOfYoutube'] = isset($this['urlOfYoutube']) && !empty($this['urlOfYoutube']) ? DataUtil::formatForDisplay($this['urlOfYoutube']) : ''; if (!empty($this['poster'])) { try { $basePath = $controllerHelper->getFileBaseFolder('movie', 'poster'); } catch (\Exception $e) { return LogUtil::registerError($e->getMessage()); } $fullPath = $basePath . $this['poster']; $this['posterFullPath'] = $fullPath; $this['posterFullPathURL'] = System::getBaseUrl() . $fullPath; // just some backwards compatibility stuff /*if (!isset($this['posterMeta']) || !is_array($this['posterMeta']) || !count($this['posterMeta'])) { // assign new meta data $this['posterMeta'] = $uploadManager->readMetaDataForFile($this['poster'], $fullPath); }*/ } $this['widthOfMovie'] = (int) (isset($this['widthOfMovie']) && !empty($this['widthOfMovie']) ? DataUtil::formatForDisplay($this['widthOfMovie']) : 0); $this['heightOfMovie'] = (int) (isset($this['heightOfMovie']) && !empty($this['heightOfMovie']) ? DataUtil::formatForDisplay($this['heightOfMovie']) : 0); $this->prepareItemActions(); return true; }
/** * 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 MUVideo_Util_Controller($serviceManager); // determine file system information try { $basePath = $controllerHelper->getFileBaseFolder($objectType, $fieldName); } catch (\Exception $e) { LogUtil::registerError($e->getMessage()); } $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('MUVideo'); $fullObjectId = $objectType . '-' . $objectId; $manager->removeImageThumbs($filePath, $fullObjectId); } // remove original file if (!unlink($filePath)) { return false; } $objectData[$fieldName] = ''; $objectData[$fieldName . 'Meta'] = array(); return $objectData; }