33
0
mirror of https://github.com/joomla-extensions/patchtester.git synced 2024-11-17 02:25:11 +00:00
patchtester/administrator/components/com_patchtester/script.php

171 lines
4.0 KiB
PHP
Raw Normal View History

<?php
/**
2015-12-05 17:43:54 +00:00
* Patch testing component for the Joomla! CMS
*
2016-02-20 16:35:10 +00:00
* @copyright Copyright (C) 2011 - 2012 Ian MacLennan, Copyright (C) 2013 - 2016 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later
*/
/**
* Installation class to perform additional changes during install/uninstall/update
*
2015-12-05 17:43:54 +00:00
* @since 2.0
*/
class Com_PatchtesterInstallerScript extends JInstallerScript
{
/**
* Array of templates with supported overrides
*
* @var array
* @since 2.0
*/
protected $templateOverrides = array('hathor');
/**
* Extension script constructor.
*
* @since 3.0.0
*/
public function __construct()
{
2016-10-31 00:31:25 +00:00
$this->minimumJoomla = '3.7';
$this->minimumPhp = JOOMLA_MINIMUM_PHP;
$this->deleteFolders = array(
'/administrator/components/com_patchtester/PatchTester/Table',
2016-07-30 20:23:14 +00:00
'/components/com_patchtester',
);
}
/**
* Function to perform changes during install
*
* @param JInstallerAdapterComponent $parent The class calling this method
*
* @return void
*
* @since 2.0
*/
public function install($parent)
{
$this->copyLayouts();
}
/**
* Function to perform changes during update
*
* @param JInstallerAdapterComponent $parent The class calling this method
*
* @return void
*
* @since 2.0
*/
public function update($parent)
{
$this->copyLayouts();
}
/**
* Function to perform changes during uninstall
*
* @param JInstallerAdapterComponent $parent The class calling this method
*
* @return void
*
* @since 2.0
*/
public function uninstall($parent)
{
jimport('joomla.filesystem.folder');
// 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
if (!JFolder::delete($overrideFolder))
{
$errorTemplates[] = ucfirst($template);
}
}
}
// If we couldn't remove any overrides, notify the user
if (count($errorTemplates) > 0)
{
JFactory::getApplication()->enqueueMessage(JText::sprintf('COM_PATCHTESTER_COULD_NOT_REMOVE_OVERRIDES', implode(', ', $errorTemplates)));
}
}
/**
* Function to perform changes during postflight
*
* @param string $type The action being performed
* @param JInstallerAdapterComponent $parent The class calling this method
*
* @return void
*
* @since 3.0.0
*/
public function postflight($type, $parent)
{
$this->removeFiles();
}
/**
* Function to copy layout overrides for core templates at install or update
*
* @return void
*
* @since 2.0
*/
private function copyLayouts()
{
jimport('joomla.filesystem.folder');
// 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
{
if (!JFolder::copy($source, $destination, '', true))
{
$errorTemplates[] = ucfirst($template);
}
}
catch (RuntimeException $exception)
{
$errorTemplates[] = ucfirst($template);
}
}
}
// If we couldn't remove any overrides, notify the user
if (count($errorTemplates) > 0)
{
JFactory::getApplication()->enqueueMessage(JText::sprintf('COM_PATCHTESTER_COULD_NOT_INSTALL_OVERRIDES', implode(', ', $errorTemplates)));
}
}
}