Example #1
0
 /**
  * Method to save the form data.
  *
  * @param    array    $data     The form data.
  * @param    boolean  $auto     true when the data comes from auto monitoring
  * @param    boolean  $import   true when the data comes from 1.9.x import process   
  * @return    boolean    True on success.
  */
 public function save($data, $auto = false, $import = false, $restore_in_progress = false)
 {
     global $jlistConfig;
     $result = false;
     // Initialise variables;
     $dispatcher = JDispatcher::getInstance();
     $table = $this->getTable();
     $pk = !empty($data['file_id']) ? $data['file_id'] : (int) $this->getState($this->getName() . '.file_id');
     $isNew = true;
     $jinput = JFactory::getApplication()->input;
     // Include the content plugins for the on save events.
     JPluginHelper::importPlugin('content');
     // Load the row if saving an existing download. Not when auto monitoring is activated (also use for import from old version)
     if ($pk > 0 && !$auto || $pk > 0 && $restore_in_progress) {
         $table->load($pk);
         $isNew = false;
     }
     // Alter the title for save as copy
     if ($jinput->get('task') == 'save2copy') {
         list($title, $alias) = $table->buildNewTitle($data['file_alias'], $data['file_title']);
         $data['file_title'] = $title;
         $data['file_alias'] = $alias;
     }
     if (!isset($data['rules'])) {
         $data['rules'] = array('core.create' => array(), 'core.delete' => array(), 'core.edit' => array(), 'core.edit.state' => array(), 'core.edit.own' => array(), 'download' => array());
     }
     if (!empty($data['tags']) && $data['tags'][0] != '') {
         $table->newTags = $data['tags'];
     }
     // Bind the data.
     if (!$table->bind($data)) {
         $this->setError($table->getError());
         return false;
     }
     // Prepare the row for saving
     $this->prepareTable($table);
     // Check the data and check the selected files and handle it.
     if (!$table->checkData($isNew, $auto)) {
         $this->setError($table->getError());
         return false;
     }
     // Trigger the onContentBeforeSave event.
     $result = $dispatcher->trigger($this->event_before_save, array($this->option . '.' . $this->name, &$table, $isNew));
     if (in_array(false, $result, true)) {
         $this->setError($table->getError());
         return false;
     }
     // Store the data.
     if ($import === true) {
         // set off this
         $table->set('_autoincrement', false);
     }
     if (!$table->store()) {
         $this->setError($table->getError());
         return false;
     } else {
         // folder handling functionality
         /*if (!$table->checkCategoryFolder()) {
               $this->setError(JText::_('COM_JDOWNLOADS_CATSEDIT_ERROR_CHECK_FOLDER'));
               return false;
           } */
         if (!$auto) {
             // Update only the log table when we have a new download creation in frontend
             $app = JFactory::getApplication();
             if ($app->isSite() && $isNew) {
                 $upload_data = new stdClass();
                 $upload_data->file_id = $table->file_id;
                 $upload_data->url_download = $table->url_download;
                 $upload_data->file_title = $table->file_title;
                 $upload_data->size = $table->size;
                 JDHelper::updateLog($type = 2, '', $upload_data);
                 // send e-mail after new download creation in frontend
                 if ($jlistConfig['send.mailto.option.upload'] == '1') {
                     JDHelper::sendMailUpload($table);
                 }
             }
         }
     }
     // Trigger the onContentAfterSave event.
     $dispatcher->trigger($this->event_after_save, array($this->option . '.' . $this->name, &$table, $isNew));
     $this->setState($this->getName() . '.id', $table->file_id);
     // Clear the cache
     $this->cleanCache();
     return true;
 }