/** * Save content item details * * @return void */ public function savecontentTask() { // Check for request forgeries Request::checkToken(['get', 'post']); // Incoming $el = Request::getInt('el', 0); $id = Request::getInt('id', 0); $version = Request::getVar('version', ''); $params = Request::getVar('params', array(), 'request', 'array'); $attachments = Request::getVar('attachments', array(), 'request', 'array'); // Load publication model $this->model = new Models\Publication($id, $version); if (!$this->model->exists()) { throw new Exception(Lang::txt('COM_PUBLICATIONS_NOT_FOUND'), 404); return; } // Set curation $this->model->setCuration(); // Save attachments if (!empty($attachments)) { foreach ($attachments as $attachId => $attach) { $pContent = new Tables\Attachment($this->database); if ($pContent->load($attachId)) { $pContent->title = $attach['title']; $pContent->store(); } } } // Set redirect URL $url = Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&task=edit' . '&id[]=' . $id . '&version=' . $version, false); // Redirect back to publication App::redirect($url, Lang::txt('COM_PUBLICATIONS_SUCCESS_SAVED_CONTENT')); }
/** * Conversion for publications created in a non-curated flow * * @param object $pub * @return boolean */ public function convertToCuration($pub = NULL) { $pub = $pub ? $pub : $this->_pub; $oldFlow = false; // Load attachments $pub->attachments(); if (!isset($pub->_attachments) || empty($pub->_attachments['elements'])) { // Nothing to convert return false; } // Get supporting docs element manifest $sElements = self::getElements(2); $sElement = $sElements ? $sElements[0] : NULL; // Loop through attachments foreach ($pub->_attachments['elements'] as $elementId => $elementAttachments) { if (empty($elementAttachments)) { continue; } // Check if any attachments are missing element id foreach ($elementAttachments as $elAttach) { if ($elAttach->element_id == 0) { // Save elementid $row = new Tables\Attachment($this->_db); if ($row->load($elAttach->id)) { $markId = $elAttach->role != 1 && $sElement ? $sElement->id : $elementId; $row->element_id = $markId; $row->store(); } $oldFlow = true; // will need to make further checks } } } if (!$oldFlow) { return false; } // Get gallery element manifest $elements = self::getElements(3); $element = $elements ? $elements[0] : NULL; // Retrieve screenshots $pScreenshot = new Tables\Screenshot($this->_db); $shots = $pScreenshot->getScreenshots($pub->version_id); // Transfer gallery files to the right location if ($element && $shots) { // Get attachment type model $attModel = new Attachments($this->_db); $fileAttach = $attModel->loadAttach('file'); // Set configs $configs = $fileAttach->getConfigs($element->manifest->params, $element->id, $pub, $element->block); // Get gallery path $galleryPath = Helpers\Html::buildPubPath($pub->id, $pub->version_id, '', 'gallery', 1); if (is_dir($galleryPath)) { foreach ($shots as $shot) { $objPA = new Tables\Attachment($this->_db); if (is_file($galleryPath . DS . $shot->srcfile) && !$objPA->loadElementAttachment($pub->version_id, array('path' => $shot->filename), $element->id, 'file', $element->manifest->params->role)) { $objPA = new Tables\Attachment($this->_db); $objPA->publication_id = $pub->id; $objPA->publication_version_id = $pub->version_id; $objPA->path = $shot->filename; $objPA->type = 'file'; $objPA->created_by = User::get('id'); $objPA->created = Date::toSql(); $objPA->role = $element->manifest->params->role; $objPA->element_id = $element->id; $objPA->ordering = $shot->ordering; if (!$objPA->store()) { continue; } // Check if names is already used $suffix = $fileAttach->checkForDuplicate($configs->path . DS . $objPA->path, $objPA, $configs); // Save params if applicable if ($suffix) { $objPA->params = 'suffix=' . $suffix . "\n"; } // Copy file into the right spot $configs->copyFrom = $galleryPath . DS . $shot->srcfile; if (!$fileAttach->publishAttachment($objPA, $pub, $configs)) { $objPA->delete(); } } } } } // Check if published version has curation manifest saved $row = new Tables\Version($this->_db); if ($pub->state == 1 && !$pub->curation) { if ($row->load($pub->version_id)) { $row->curation = json_encode($this->_manifest); $row->store(); } } // Mark as curated $row->saveParam($row->id, 'curated', 1); return true; }