2021-03-05 03:08:47 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @package Joomla.Component.Builder
|
|
|
|
*
|
|
|
|
* @created 30th April, 2015
|
|
|
|
* @author Llewellyn van der Merwe <http://www.joomlacomponentbuilder.com>
|
|
|
|
* @github Joomla Component Builder <https://github.com/vdm-io/Joomla-Component-Builder>
|
|
|
|
* @copyright Copyright (C) 2015 - 2019 Vast Development Method. All rights reserved.
|
|
|
|
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
// No direct access to this file
|
|
|
|
defined('_JEXEC') or die('Restricted access');
|
|
|
|
?>
|
|
|
|
###BOM###
|
|
|
|
|
|
|
|
// No direct access to this file
|
|
|
|
defined('_JEXEC') or die('Restricted access');
|
|
|
|
|
2024-03-02 20:10:30 +00:00
|
|
|
use Joomla\CMS\Factory;
|
|
|
|
use Joomla\CMS\Language\Text;
|
2021-03-08 22:36:30 +00:00
|
|
|
use Joomla\CMS\Filesystem\File;
|
|
|
|
use Joomla\CMS\Filesystem\Folder;
|
2021-10-19 01:30:46 +00:00
|
|
|
use Joomla\CMS\Installer\Adapter\ComponentAdapter;
|
2024-03-02 20:10:30 +00:00
|
|
|
use Joomla\CMS\Version;
|
|
|
|
use Joomla\CMS\HTML\HTMLHelper as Html;
|
|
|
|
HTML::_('bootstrap.renderModal');
|
2021-03-05 03:08:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Script File of ###Component### Component
|
|
|
|
*/
|
2024-03-02 20:10:30 +00:00
|
|
|
class Com_###Component###InstallerScript
|
2021-03-05 03:08:47 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
2024-03-02 20:10:30 +00:00
|
|
|
* @param ComponentAdapter $parent The object responsible for running this script
|
2021-03-05 03:08:47 +00:00
|
|
|
*/
|
2021-10-19 01:30:46 +00:00
|
|
|
public function __construct(ComponentAdapter $parent) {}
|
2021-03-05 03:08:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Called on installation
|
|
|
|
*
|
2021-10-19 01:30:46 +00:00
|
|
|
* @param ComponentAdapter $parent The object responsible for running this script
|
2021-03-05 03:08:47 +00:00
|
|
|
*
|
|
|
|
* @return boolean True on success
|
|
|
|
*/
|
2021-10-19 01:30:46 +00:00
|
|
|
public function install(ComponentAdapter $parent) {}
|
2021-03-05 03:08:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Called on uninstallation
|
|
|
|
*
|
2021-10-19 01:30:46 +00:00
|
|
|
* @param ComponentAdapter $parent The object responsible for running this script
|
2021-03-05 03:08:47 +00:00
|
|
|
*/
|
2021-10-19 01:30:46 +00:00
|
|
|
public function uninstall(ComponentAdapter $parent)
|
2021-03-05 03:08:47 +00:00
|
|
|
{###UNINSTALLSCRIPT###
|
|
|
|
// little notice as after service, in case of bad experience with component.
|
|
|
|
echo '<h2>Did something go wrong? Are you disappointed?</h2>
|
|
|
|
<p>Please let me know at <a href="mailto:###AUTHOREMAIL###">###AUTHOREMAIL###</a>.
|
|
|
|
<br />We at ###COMPANYNAME### are committed to building extensions that performs proficiently! You can help us, really!
|
|
|
|
<br />Send me your thoughts on improvements that is needed, trust me, I will be very grateful!
|
|
|
|
<br />Visit us at <a href="###AUTHORWEBSITE###" target="_blank">###AUTHORWEBSITE###</a> today!</p>';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called on update
|
|
|
|
*
|
2021-10-19 01:30:46 +00:00
|
|
|
* @param ComponentAdapter $parent The object responsible for running this script
|
2021-03-05 03:08:47 +00:00
|
|
|
*
|
|
|
|
* @return boolean True on success
|
|
|
|
*/
|
2021-10-19 01:30:46 +00:00
|
|
|
public function update(ComponentAdapter $parent){}
|
2021-03-05 03:08:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Called before any type of action
|
|
|
|
*
|
|
|
|
* @param string $type Which action is happening (install|uninstall|discover_install|update)
|
2021-10-19 01:30:46 +00:00
|
|
|
* @param ComponentAdapter $parent The object responsible for running this script
|
2021-03-05 03:08:47 +00:00
|
|
|
*
|
|
|
|
* @return boolean True on success
|
|
|
|
*/
|
2021-10-19 01:30:46 +00:00
|
|
|
public function preflight($type, ComponentAdapter $parent)
|
2021-03-05 03:08:47 +00:00
|
|
|
{
|
|
|
|
// get application
|
2024-03-02 20:10:30 +00:00
|
|
|
$app = Factory::getApplication();
|
2021-03-05 03:08:47 +00:00
|
|
|
// is redundant or so it seems ...hmmm let me know if it works again
|
|
|
|
if ($type === 'uninstall')
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// the default for both install and update
|
2024-03-02 20:10:30 +00:00
|
|
|
$jversion = new Version();
|
2021-03-05 03:08:47 +00:00
|
|
|
if (!$jversion->isCompatible('3.8.0'))
|
|
|
|
{
|
|
|
|
$app->enqueueMessage('Please upgrade to at least Joomla! 3.8.0 before continuing!', 'error');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// do any updates needed
|
|
|
|
if ($type === 'update')
|
|
|
|
{###PREUPDATESCRIPT###
|
|
|
|
}
|
|
|
|
// do any install needed
|
|
|
|
if ($type === 'install')
|
|
|
|
{###PREINSTALLSCRIPT###
|
|
|
|
}
|
|
|
|
// check if the PHPExcel stuff is still around
|
2021-03-08 22:36:30 +00:00
|
|
|
if (File::exists(JPATH_ADMINISTRATOR . '/components/com_###component###/helpers/PHPExcel.php'))
|
2021-03-05 03:08:47 +00:00
|
|
|
{
|
|
|
|
// We need to remove this old PHPExcel folder
|
|
|
|
$this->removeFolder(JPATH_ADMINISTRATOR . '/components/com_###component###/helpers/PHPExcel');
|
|
|
|
// We need to remove this old PHPExcel file
|
2021-03-08 22:36:30 +00:00
|
|
|
File::delete(JPATH_ADMINISTRATOR . '/components/com_###component###/helpers/PHPExcel.php');
|
2021-03-05 03:08:47 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called after any type of action
|
|
|
|
*
|
|
|
|
* @param string $type Which action is happening (install|uninstall|discover_install|update)
|
2021-10-19 01:30:46 +00:00
|
|
|
* @param ComponentAdapter $parent The object responsible for running this script
|
2021-03-05 03:08:47 +00:00
|
|
|
*
|
|
|
|
* @return boolean True on success
|
|
|
|
*/
|
2021-10-19 01:30:46 +00:00
|
|
|
public function postflight($type, ComponentAdapter $parent)
|
2021-03-05 03:08:47 +00:00
|
|
|
{
|
|
|
|
// get application
|
2024-03-02 20:10:30 +00:00
|
|
|
$app = Factory::getApplication();###MOVEFOLDERSSCRIPT###
|
2021-03-05 03:08:47 +00:00
|
|
|
// set the default component settings
|
|
|
|
if ($type === 'install')
|
|
|
|
{###POSTINSTALLSCRIPT###
|
|
|
|
}
|
|
|
|
// do any updates needed
|
|
|
|
if ($type === 'update')
|
|
|
|
{###POSTUPDATESCRIPT###
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-07-17 00:39:35 +00:00
|
|
|
* Remove folders with files (with ignore options)
|
2024-03-02 20:10:30 +00:00
|
|
|
*
|
2024-07-17 00:39:35 +00:00
|
|
|
* @param string $dir The path to the folder to remove.
|
|
|
|
* @param array|null $ignore The folders and files to ignore and not remove.
|
2024-03-02 20:10:30 +00:00
|
|
|
*
|
2024-07-17 00:39:35 +00:00
|
|
|
* @return bool True if all specified files/folders are removed, false otherwise.
|
|
|
|
* @since 3.2.2
|
2021-03-05 03:08:47 +00:00
|
|
|
*/
|
2024-07-17 00:39:35 +00:00
|
|
|
protected function removeFolder(string $dir, ?array $ignore = null): bool
|
2021-03-05 03:08:47 +00:00
|
|
|
{
|
2024-07-17 00:39:35 +00:00
|
|
|
if (!is_dir($dir))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$it = new \RecursiveDirectoryIterator($dir, \FilesystemIterator::SKIP_DOTS);
|
|
|
|
$it = new \RecursiveIteratorIterator($it, \RecursiveIteratorIterator::CHILD_FIRST);
|
|
|
|
|
|
|
|
// Remove trailing slash
|
|
|
|
$dir = rtrim($dir, '/');
|
|
|
|
|
|
|
|
foreach ($it as $file)
|
2021-03-05 03:08:47 +00:00
|
|
|
{
|
2024-07-17 00:39:35 +00:00
|
|
|
$filePath = $file->getPathname();
|
|
|
|
$relativePath = str_replace($dir . '/', '', $filePath);
|
|
|
|
|
|
|
|
if ($ignore !== null && in_array($relativePath, $ignore, true))
|
2021-03-05 03:08:47 +00:00
|
|
|
{
|
2024-07-17 00:39:35 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($file->isDir())
|
|
|
|
{
|
|
|
|
Folder::delete($filePath);
|
2021-03-05 03:08:47 +00:00
|
|
|
}
|
2024-07-17 00:39:35 +00:00
|
|
|
else
|
2021-03-05 03:08:47 +00:00
|
|
|
{
|
2024-07-17 00:39:35 +00:00
|
|
|
File::delete($filePath);
|
2021-03-05 03:08:47 +00:00
|
|
|
}
|
|
|
|
}
|
2024-07-17 00:39:35 +00:00
|
|
|
|
|
|
|
// Delete the root folder if there are no ignored files/folders left
|
|
|
|
if ($ignore === null || $this->isDirEmpty($dir, $ignore))
|
|
|
|
{
|
|
|
|
return Folder::delete($dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a directory is empty considering ignored files/folders.
|
|
|
|
*
|
|
|
|
* @param string $dir The path to the folder to check.
|
|
|
|
* @param array $ignore The folders and files to ignore.
|
|
|
|
*
|
|
|
|
* @return bool True if the directory is empty or contains only ignored items, false otherwise.
|
|
|
|
* @since 3.2.1
|
|
|
|
*/
|
|
|
|
protected function isDirEmpty(string $dir, array $ignore): bool
|
|
|
|
{
|
|
|
|
$it = new \RecursiveDirectoryIterator($dir, \FilesystemIterator::SKIP_DOTS);
|
|
|
|
foreach ($it as $file)
|
|
|
|
{
|
|
|
|
$relativePath = str_replace($dir . '/', '', $file->getPathname());
|
|
|
|
if (!in_array($relativePath, $ignore, true))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
2021-03-05 03:08:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if have an array with a length
|
|
|
|
*
|
2024-03-02 20:10:30 +00:00
|
|
|
* @input array The array to check
|
2021-03-05 03:08:47 +00:00
|
|
|
*
|
|
|
|
* @returns bool/int number of items in array on success
|
2024-07-17 00:39:35 +00:00
|
|
|
* @since 3.2.2
|
2021-03-05 03:08:47 +00:00
|
|
|
*/
|
|
|
|
protected function checkArray($array, $removeEmptyString = false)
|
|
|
|
{
|
|
|
|
if (isset($array) && is_array($array) && ($nr = count((array)$array)) > 0)
|
|
|
|
{
|
|
|
|
// also make sure the empty strings are removed
|
|
|
|
if ($removeEmptyString)
|
|
|
|
{
|
|
|
|
foreach ($array as $key => $string)
|
|
|
|
{
|
|
|
|
if (empty($string))
|
|
|
|
{
|
|
|
|
unset($array[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->checkArray($array, false);
|
|
|
|
}
|
|
|
|
return $nr;
|
|
|
|
}
|
|
|
|
return false;
|
2024-07-17 00:39:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensures that a class in the namespace is available.
|
|
|
|
* If the class is not already loaded, it attempts to load it via the specified autoloader.
|
|
|
|
*
|
|
|
|
* @param string $className The fully qualified name of the class to check.
|
|
|
|
*
|
|
|
|
* @return bool True if the class exists or was successfully loaded, false otherwise.
|
|
|
|
* @since 3.2.2
|
|
|
|
*/
|
|
|
|
protected function classExists(string $className): bool
|
|
|
|
{
|
|
|
|
if (!class_exists($className, true))
|
|
|
|
{
|
|
|
|
###THREE_POWER_AUTOLOADER###
|
|
|
|
|
|
|
|
// Check again if the class now exists after requiring the autoloader
|
|
|
|
if (!class_exists($className, true))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
2024-04-21 22:59:42 +00:00
|
|
|
}###INSTALLERMETHODS###
|
2021-03-05 03:08:47 +00:00
|
|
|
}
|