Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to use scriptfile with packages #36

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
163 changes: 161 additions & 2 deletions libraries/joomla/installer/adapters/package.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,64 @@ public function install()
$group = (string) $this->manifest->packagename;
if (!empty($group))
{
// TODO: Remark this location
$this->parent->setPath('extension_root', JPATH_ROOT . '/packages/' . implode(DS, explode('/', $group)));
$this->parent->setPath('extension_root', JPATH_MANIFESTS . '/packages/' . implode(DS, explode('/', $group)));
}
else
{
$this->parent->abort(JText::sprintf('JLIB_INSTALLER_ABORT_PACK_INSTALL_NO_PACK', JText::_('JLIB_INSTALLER_' . strtoupper($this->route))));
return false;
}

/**
* ---------------------------------------------------------------------------------------------
* Installer Trigger Loading
* ---------------------------------------------------------------------------------------------
*/
// If there is an manifest class file, lets load it; we'll copy it later (don't have dest yet)
$this->scriptElement = $this->manifest->scriptfile;
$manifestScript = (string) $this->manifest->scriptfile;

if ($manifestScript)
{
$manifestScriptFile = $this->parent->getPath('source') . '/' . $manifestScript;

if (is_file($manifestScriptFile))
{
// load the file
include_once $manifestScriptFile;
}

// Set the class name
$classname = $element . 'InstallerScript';

if (class_exists($classname))
{
// create a new instance
$this->parent->manifestClass = new $classname($this);
// and set this so we can copy it later
$this->set('manifest_script', $manifestScript);
// Note: if we don't find the class, don't bother to copy the file
}
}

// run preflight if possible (since we know we're not an update)
ob_start();
ob_implicit_flush(false);

if ($this->parent->manifestClass && method_exists($this->parent->manifestClass, 'preflight'))
{
if ($this->parent->manifestClass->preflight($this->route, $this) === false)
{
// Install failed, rollback changes
$this->parent->abort(JText::_('JLIB_INSTALLER_ABORT_PACKAGE_INSTALL_CUSTOM_INSTALL_FAILURE'));

return false;
}
}

$msg = ob_get_contents(); // create msg object; first use here
ob_end_clean();

// Filesystem Processing Section

if ($folder = $files->attributes()->folder)
Expand All @@ -114,6 +163,7 @@ public function install()
// Install all necessary files
if (count($this->manifest->files->children()))
{
$i = 0;
foreach ($this->manifest->files->children() as $child)
{
$file = $source . '/' . $child;
Expand Down Expand Up @@ -141,6 +191,14 @@ public function install()
);
return false;
}
else
{
$results[$i] = array(
'name' => $tmpInstaller->manifest->name,
'result' => $tmpInstaller->install($package['dir'])
);
}
$i++;
}
}
else
Expand Down Expand Up @@ -187,6 +245,24 @@ public function install()

// Finalization and Cleanup Section

// Start Joomla! 1.6
ob_start();
ob_implicit_flush(false);

if ($this->parent->manifestClass && method_exists($this->parent->manifestClass, $this->route))
{
if ($this->parent->manifestClass->{$this->route}($this) === false)
{
// Install failed, rollback changes
$this->parent->abort(JText::_('JLIB_INSTALLER_ABORT_FILE_INSTALL_CUSTOM_INSTALL_FAILURE'));

return false;
}
}

$msg .= ob_get_contents(); // append messages
ob_end_clean();

// Lastly, we will copy the manifest file to its appropriate place.
$manifest = array();
$manifest['src'] = $this->parent->getPath('manifest');
Expand All @@ -200,6 +276,49 @@ public function install()
);
return false;
}

// If there is a manifest script, let's copy it.
if ($this->get('manifest_script'))
{
// First, we have to create a folder for the script if one isn't present
$created = false;

if (!file_exists($this->parent->getPath('extension_root')))
{
JFolder::create($this->parent->getPath('extension_root'));
}

$path['src'] = $this->parent->getPath('source') . '/' . $this->get('manifest_script');
$path['dest'] = $this->parent->getPath('extension_root') . '/' . $this->get('manifest_script');

if (!file_exists($path['dest']) || $this->parent->getOverwrite())
{
if (!$this->parent->copyFiles(array($path)))
{
// Install failed, rollback changes
$this->parent->abort(JText::_('JLIB_INSTALLER_ABORT_PACKAGE_INSTALL_MANIFEST'));

return false;
}
}
}

// And now we run the postflight
ob_start();
ob_implicit_flush(false);

if ($this->parent->manifestClass && method_exists($this->parent->manifestClass, 'postflight'))
{
$this->parent->manifestClass->postflight($this->route, $this, $results);
}

$msg .= ob_get_contents(); // append messages
ob_end_clean();

if ($msg != '')
{
$this->parent->set('extension_message', $msg);
}
return $row->extension_id;
}

Expand Down Expand Up @@ -278,6 +397,46 @@ function uninstall($id)
return false;
}

// If there is an manifest class file, let's load it
$this->scriptElement = $manifest->scriptfile;
$manifestScript = (string) $manifest->scriptfile;

if ($manifestScript)
{
$manifestScriptFile = $this->parent->getPath('extension_root') . '/' . $manifestScript;

if (is_file($manifestScriptFile))
{
// Load the file
include_once $manifestScriptFile;
}

// Set the class name
$classname = $row->element . 'InstallerScript';

if (class_exists($classname))
{
// Create a new instance
$this->parent->manifestClass = new $classname($this);
// And set this so we can copy it later
$this->set('manifest_script', $manifestScript);

// Note: if we don't find the class, don't bother to copy the file
}
}

ob_start();
ob_implicit_flush(false);

// Run uninstall if possible
if ($this->parent->manifestClass && method_exists($this->parent->manifestClass, 'uninstall'))
{
$this->parent->manifestClass->uninstall($this);
}

$msg = ob_get_contents();
ob_end_clean();

$error = false;
foreach ($manifest->filelist as $extension)
{
Expand Down
6 changes: 6 additions & 0 deletions libraries/joomla/installer/packagemanifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ class JPackageManifest extends JObject
*/
var $packagerurl = '';

/**
* @var string scriptfile Scriptfile for the package
*/
protected $scriptfile = '';

/**
* @var string update Update site for the package
*/
Expand Down Expand Up @@ -119,6 +124,7 @@ function loadManifestFromXML($xmlfile)
$this->description = (string) $xml->description;
$this->packager = (string) $xml->packager;
$this->packagerurl = (string) $xml->packagerurl;
$this->scriptfile = (string) $xml->scriptfile;
$this->version = (string) $xml->version;

if (isset($xml->files->file) && count($xml->files->file))
Expand Down