/** * Migrate a single product files * * @param TiendaTableProduct $product * @param array $data */ private function _migrateFiles($product_id, $files) { foreach ($files->children() as $file) { // Add the File $table = JTable::getInstance('ProductFiles', 'TiendaTable'); $table->bind($this->simpleXml2Array($file)); $table->product_id = $product_id; // Now the files on the zip have to be linked $dest_dir = TiendaHelperProduct::getFilePath($product_id); $source_dir = $this->_temp_dir . DS . 'files' . DS; $filename = $table->productfile_name; $path = $dest_dir . DS . $filename; $namebits = explode('.', $filename); $extension = $namebits[count($namebits) - 1]; $table->productfile_extension = $extension; $table->productfile_path = $path; // If the files exists & the copy is successfull, save the file if (JFile::exists($source_dir . $filename)) { if (JFile::copy($source_dir . $filename, $dest_dir . DS . $filename)) { $table->save(); } } } }
/** * Creates a file from disk and redirects * * @return unknown_type */ function createfilefromdisk() { $this->set('suffix', 'productfiles'); $model = $this->getModel($this->get('suffix')); $file = JRequest::getVar('createproductfileserver_file'); $row = $model->getTable(); $row->product_id = JRequest::getVar('id'); $row->productfile_name = JRequest::getVar('createproductfileserver_name'); $row->productfile_enabled = JRequest::getVar('createproductfileserver_enabled'); $row->purchase_required = JRequest::getVar('createproductfileserver_purchaserequired'); $row->max_download = JRequest::getInt('createproductfileserver_max_download', -1); if (empty($row->productfile_name)) { $row->productfile_name = $file; } Tienda::load("TiendaHelperProduct", 'helpers.product'); $path = TiendaHelperProduct::getFilePath($row->product_id) . DS . $file; $namebits = explode('.', $file); $extension = $namebits[count($namebits) - 1]; $row->productfile_extension = $extension; $row->productfile_path = $path; if ($row->save()) { $model->clearCache(); $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('onAfterSave' . $this->get('suffix'), array($row)); $this->messagetype = 'notice'; $this->message = JText::_('COM_TIENDA_UPLOAD_WAS_SUCCESSFULL'); } else { $this->messagetype = 'notice'; $this->message = JText::_('COM_TIENDA_SAVE_FAILED') . " - " . $row->getError(); } $redirect = "index.php?option=com_tienda&view=products&task=setfiles&id={$row->product_id}&tmpl=component"; $redirect = JRoute::_($redirect, false); $this->setRedirect($redirect, $this->message, $this->messagetype); }