/** * Export the package * * @param array $ids package ids to export * * @return void */ public function export($ids = array()) { jimport('joomla.filesystem.archive'); foreach ($ids as $id) { $row = $this->getTable(); $row->load($id); $this->outputPath = JPATH_ROOT . '/tmp/' . $this->getComponentName($row) . '/'; $json = $row->params; $row->params = json_decode($row->params); $row->blocks = $row->params->canvas->blocks; $componentZipPath = $this->outputPath . 'packages/com_' . $this->getComponentName($row) . '.zip'; $pkgName = 'pkg_' . $this->getComponentName($row, true) . '.zip'; $packageZipPath = $this->outputPath . $pkgName; if (JFile::exists($componentZipPath)) { JFile::delete($componentZipPath); } $filenames = array(); $row2 = clone $row; $row2->params = $json; $filenames[] = $this->makeInstallSQL($row); $filenames[] = $this->makeUnistallSQL($row); $filenames[] = $this->makeXML($row); $filenames[] = $this->makeComponentManifestClass($row2); $this->copySkeleton($row, $filenames); $this->alterViewXML($row); $archive = JArchive::getAdapter('zip'); $files = array(); $this->addFiles($filenames, $files, $this->outputPath); $ok = $archive->create($componentZipPath, $files); if (!$ok) { throw new RuntimeException('Unable to create component zip in ' . $componentZipPath, 500); } // Make form module $archive = JArchive::getAdapter('zip'); $formModuleFiles = $this->formModuleFiles($row); $formModuleZipPath = $this->outputPath . 'packages/mod_' . $this->getComponentName($row) . '_form.zip'; $ok = $archive->create($formModuleZipPath, $formModuleFiles); if (!$ok) { throw new RuntimeException('Unable to form module zip in ' . $componentZipPath, 500); } // Copy that to root $ok = JFile::copy($componentZipPath, $this->outputPath . 'com_' . $this->getComponentName($row) . '.zip'); // Now lets create the Joomla install package $plugins = $this->findPlugins($row); $this->zipPlugins($row, $plugins); $filenames = FArrayHelper::extract($plugins, 'fullfile'); $filenames[] = $componentZipPath; // Have to add this LAST to filenames $filenames[] = $this->makePackageXML($row, $plugins); $files = array(); $this->addFiles($filenames, $files, $this->outputPath); $ok = $archive->create($packageZipPath, $files); if (!$ok) { throw new RuntimeException('Unable to create zip in ' . $componentZipPath, 500); } // $this->triggerDownload($pkgName, $packageZipPath); // $this->cleanUp($pkgName); } }
public function export($ids = array()) { //JModel::addIncludePath(COM_FABRIK_FRONTEND.DS.'models'); jimport('joomla.filesystem.archive'); foreach ($ids as $id) { $row = $this->getTable(); $row->load($id); $this->outputPath = JPATH_ROOT . DS . 'tmp' . DS . $this->getComponentName($row); $json = $row->params; $row->params = json_decode($row->params); $row->blocks = $row->params->canvas->blocks; $componentZipPath = $this->outputPath . DS . 'packages' . DS . 'com_' . $this->getComponentName($row) . '.zip'; $pkgName = 'pkg_' . $this->getComponentName($row) . '.zip'; $packageZipPath = $this->outputPath . DS . $pkgName; if (JFile::exists($componentZipPath)) { JFile::delete($componentZipPath); } $filenames = array(); $row2 = clone $row; $row2->params = $json; $filenames[] = $this->makeXML($row); $filenames[] = $this->makeInstallSQL($row); $filenames[] = $this->makeUnistallSQL($row); $filenames[] = $this->makeMetaSQL($row2); $this->copySkeleton($row, $filenames); $archive = JArchive::getAdapter('zip'); $files = array(); $this->addFiles($filenames, $files, $this->outputPath . DS); $ok = $archive->create($componentZipPath, $files); if (!$ok) { JError::raiseError(500, 'Unable to create zip in ' . $componentZipPath); } //copy that to root $ok = JFile::copy($componentZipPath, $this->outputPath . DS . 'com_' . $this->getComponentName($row) . '.zip'); // now lets create the Joomla install package $plugins = $this->findPlugins($row); $this->zipPlugins($row, $plugins); $filenames = FArrayHelper::extract($plugins, 'fullfile'); $filenames[] = $componentZipPath; $filenames[] = $this->makePackageXML($row, $plugins); $files = array(); $this->addFiles($filenames, $files, $this->outputPath . DS); $ok = $archive->create($packageZipPath, $files); if (!$ok) { JError::raiseError(500, 'Unable to create zip in ' . $componentZipPath); } //$this->triggerDownload($pkgName, $packageZipPath); //$this->cleanUp($pkgName); } }