2013-09-29 01:43:51 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2015-12-05 17:43:54 +00:00
|
|
|
* Patch testing component for the Joomla! CMS
|
2013-09-29 01:43:51 +00:00
|
|
|
*
|
2018-09-01 14:32:23 +00:00
|
|
|
* @copyright Copyright (C) 2011 - 2012 Ian MacLennan, Copyright (C) 2013 - 2018 Open Source Matters, Inc. All rights reserved.
|
2013-09-29 01:43:51 +00:00
|
|
|
* @license GNU General Public License version 2 or later
|
|
|
|
*/
|
|
|
|
|
2017-08-17 23:22:01 +00:00
|
|
|
use Joomla\CMS\Factory;
|
2019-08-28 01:20:49 +00:00
|
|
|
use Joomla\CMS\Filesystem\Folder;
|
2017-08-17 23:22:01 +00:00
|
|
|
use Joomla\CMS\Installer\Adapter\ComponentAdapter;
|
|
|
|
use Joomla\CMS\Installer\InstallerScript;
|
2019-08-28 01:20:49 +00:00
|
|
|
use Joomla\CMS\Language\Text;
|
2017-08-17 23:22:01 +00:00
|
|
|
|
2013-09-29 01:43:51 +00:00
|
|
|
/**
|
|
|
|
* Installation class to perform additional changes during install/uninstall/update
|
|
|
|
*
|
2015-12-05 17:43:54 +00:00
|
|
|
* @since 2.0
|
2013-09-29 01:43:51 +00:00
|
|
|
*/
|
2017-08-17 23:22:01 +00:00
|
|
|
class Com_PatchtesterInstallerScript extends InstallerScript
|
2013-09-29 01:43:51 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Array of templates with supported overrides
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @since 2.0
|
|
|
|
*/
|
2019-08-27 23:18:54 +00:00
|
|
|
protected $templateOverrides = array('atum');
|
2013-09-29 01:43:51 +00:00
|
|
|
|
|
|
|
/**
|
2016-06-19 15:17:11 +00:00
|
|
|
* Extension script constructor.
|
2013-09-29 01:43:51 +00:00
|
|
|
*
|
2016-06-25 17:46:15 +00:00
|
|
|
* @since 3.0.0
|
2013-09-29 01:43:51 +00:00
|
|
|
*/
|
2016-06-19 15:17:11 +00:00
|
|
|
public function __construct()
|
2013-09-29 01:43:51 +00:00
|
|
|
{
|
2019-08-28 00:46:12 +00:00
|
|
|
$this->minimumJoomla = '3.9';
|
2016-06-19 15:17:11 +00:00
|
|
|
$this->minimumPhp = JOOMLA_MINIMUM_PHP;
|
2013-09-29 01:43:51 +00:00
|
|
|
|
2017-01-21 19:52:15 +00:00
|
|
|
$this->deleteFiles = array(
|
|
|
|
'/administrator/components/com_patchtester/PatchTester/View/Pulls/tmpl/default_errors.php',
|
2019-08-27 23:18:54 +00:00
|
|
|
'/administrator/templates/hathor/html/com_patchtester/pulls/default.php',
|
|
|
|
'/administrator/templates/hathor/html/com_patchtester/pulls/default_items.php',
|
2017-01-21 19:52:15 +00:00
|
|
|
);
|
|
|
|
|
2016-06-19 15:17:11 +00:00
|
|
|
$this->deleteFolders = array(
|
|
|
|
'/administrator/components/com_patchtester/PatchTester/Table',
|
2019-08-27 23:18:54 +00:00
|
|
|
'/administrator/templates/hathor/html/com_patchtester/pulls',
|
|
|
|
'/administrator/templates/hathor/html/com_patchtester',
|
2016-07-30 20:23:14 +00:00
|
|
|
'/components/com_patchtester',
|
|
|
|
);
|
2013-09-29 01:43:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to perform changes during install
|
|
|
|
*
|
2017-08-17 23:22:01 +00:00
|
|
|
* @param ComponentAdapter $parent The class calling this method
|
2013-09-29 01:43:51 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*
|
|
|
|
* @since 2.0
|
|
|
|
*/
|
|
|
|
public function install($parent)
|
|
|
|
{
|
|
|
|
$this->copyLayouts();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to perform changes during update
|
|
|
|
*
|
2017-08-17 23:22:01 +00:00
|
|
|
* @param ComponentAdapter $parent The class calling this method
|
2013-09-29 01:43:51 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*
|
|
|
|
* @since 2.0
|
|
|
|
*/
|
|
|
|
public function update($parent)
|
|
|
|
{
|
|
|
|
$this->copyLayouts();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to perform changes during uninstall
|
|
|
|
*
|
2017-08-17 23:22:01 +00:00
|
|
|
* @param ComponentAdapter $parent The class calling this method
|
2013-09-29 01:43:51 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*
|
|
|
|
* @since 2.0
|
|
|
|
*/
|
|
|
|
public function uninstall($parent)
|
|
|
|
{
|
|
|
|
// Initialize the error array
|
|
|
|
$errorTemplates = array();
|
|
|
|
|
|
|
|
// Loop the supported templates
|
|
|
|
foreach ($this->templateOverrides as $template)
|
|
|
|
{
|
|
|
|
// Set the file paths
|
|
|
|
$tmplRoot = JPATH_ADMINISTRATOR . '/templates/' . $template;
|
|
|
|
$overrideFolder = JPATH_ADMINISTRATOR . '/templates/' . $template . '/html/com_patchtester';
|
|
|
|
|
|
|
|
// Make sure the template is actually installed
|
|
|
|
if (is_dir($tmplRoot))
|
|
|
|
{
|
|
|
|
// If there's a failure in copying the overrides, log it to the error array
|
2019-08-28 01:20:49 +00:00
|
|
|
if (Folder::delete($overrideFolder))
|
2013-09-29 01:43:51 +00:00
|
|
|
{
|
|
|
|
$errorTemplates[] = ucfirst($template);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we couldn't remove any overrides, notify the user
|
|
|
|
if (count($errorTemplates) > 0)
|
|
|
|
{
|
2019-08-28 01:20:49 +00:00
|
|
|
Factory::getApplication()->enqueueMessage(Text::sprintf('COM_PATCHTESTER_COULD_NOT_REMOVE_OVERRIDES', implode(', ', $errorTemplates)));
|
2013-09-29 01:43:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-19 15:17:11 +00:00
|
|
|
/**
|
|
|
|
* Function to perform changes during postflight
|
|
|
|
*
|
2017-08-17 23:22:01 +00:00
|
|
|
* @param string $type The action being performed
|
|
|
|
* @param ComponentAdapter $parent The class calling this method
|
2016-06-19 15:17:11 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*
|
2016-06-25 17:46:15 +00:00
|
|
|
* @since 3.0.0
|
2016-06-19 15:17:11 +00:00
|
|
|
*/
|
|
|
|
public function postflight($type, $parent)
|
|
|
|
{
|
|
|
|
$this->removeFiles();
|
|
|
|
}
|
|
|
|
|
2013-09-29 01:43:51 +00:00
|
|
|
/**
|
|
|
|
* Function to copy layout overrides for core templates at install or update
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*
|
|
|
|
* @since 2.0
|
|
|
|
*/
|
|
|
|
private function copyLayouts()
|
|
|
|
{
|
|
|
|
// Initialize the error array
|
|
|
|
$errorTemplates = array();
|
|
|
|
|
|
|
|
// Loop the supported templates
|
|
|
|
foreach ($this->templateOverrides as $template)
|
|
|
|
{
|
|
|
|
// Set the file paths
|
|
|
|
$source = __DIR__ . '/' . $template;
|
|
|
|
$tmplRoot = JPATH_ADMINISTRATOR . '/templates/' . $template;
|
|
|
|
$destination = JPATH_ADMINISTRATOR . '/templates/' . $template . '/html/com_patchtester';
|
|
|
|
|
|
|
|
// Make sure the template is actually installed
|
|
|
|
if (is_dir($tmplRoot))
|
|
|
|
{
|
|
|
|
// If there's a failure in copying the overrides, log it to the error array
|
2016-01-11 20:07:56 +00:00
|
|
|
try
|
|
|
|
{
|
2019-08-28 01:20:49 +00:00
|
|
|
if (Folder::copy($source, $destination, '', true))
|
2016-01-11 20:07:56 +00:00
|
|
|
{
|
|
|
|
$errorTemplates[] = ucfirst($template);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (RuntimeException $exception)
|
2013-09-29 01:43:51 +00:00
|
|
|
{
|
|
|
|
$errorTemplates[] = ucfirst($template);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we couldn't remove any overrides, notify the user
|
|
|
|
if (count($errorTemplates) > 0)
|
|
|
|
{
|
2019-08-28 01:20:49 +00:00
|
|
|
Factory::getApplication()->enqueueMessage(Text::sprintf('COM_PATCHTESTER_COULD_NOT_INSTALL_OVERRIDES', implode(', ', $errorTemplates)));
|
2013-09-29 01:43:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|