/** * Migrate a single product files * * param CitruscartTableProduct $product * param array $data */ private function _migrateFiles($product_id, $files) { foreach ($files->children() as $file) { // Add the File $table = JTable::getInstance('ProductFiles', 'CitruscartTable'); $table->bind($this->simpleXml2Array($file)); $table->product_id = $product_id; // Now the files on the zip have to be linked $dest_dir = CitruscartHelperProduct::getFilePath($product_id); $source_dir = $this->_temp_dir . DIRECTORY_SEPARATOR . 'files' . DS; $filename = $table->productfile_name; $path = $dest_dir . DIRECTORY_SEPARATOR . $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 . DIRECTORY_SEPARATOR . $filename)) { $table->save(); } } } }
/** * Creates a file from disk and redirects * * @return unknown_type */ function createfilefromdisk() { JPluginHelper::importPlugin('citruscart'); $app = JFactory::getApplication(); $this->set('suffix', 'productfiles'); $model = $this->getModel($this->get('suffix')); $file = $app->input->get('createproductfileserver_file'); $row = $model->getTable(); $row->product_id = $app->input->get('id'); $row->productfile_name = $app->input->get('createproductfileserver_name'); $row->productfile_enabled = $app->input->get('createproductfileserver_enabled'); $row->purchase_required = $app->input->get('createproductfileserver_purchaserequired'); $row->max_download = $app->input->getInt('createproductfileserver_max_download', -1); if (empty($row->productfile_name)) { $row->productfile_name = $file; } Citruscart::load("CitruscartHelperProduct", 'helpers.product'); $path = CitruscartHelperProduct::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(); $app->triggerEvent('onAfterSave' . $this->get('suffix'), array($row)); $this->messagetype = 'notice'; $this->message = JText::_('COM_CITRUSCART_UPLOAD_WAS_SUCCESSFULL'); } else { $this->messagetype = 'notice'; $this->message = JText::_('COM_CITRUSCART_SAVE_FAILED') . " - " . $row->getError(); } $redirect = "index.php?option=com_citruscart&view=products&task=setfiles&id={$row->product_id}&tmpl=component"; $redirect = JRoute::_($redirect, false); $this->setRedirect($redirect, $this->message, $this->messagetype); }