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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove folders with files
|
2024-03-02 20:10:30 +00:00
|
|
|
*
|
2021-03-05 03:08:47 +00:00
|
|
|
* @param string $dir The path to folder to remove
|
|
|
|
* @param boolean $ignore The folders and files to ignore and not remove
|
|
|
|
*
|
|
|
|
* @return boolean True in all is removed
|
2024-03-02 20:10:30 +00:00
|
|
|
*
|
2021-03-05 03:08:47 +00:00
|
|
|
*/
|
|
|
|
protected function removeFolder($dir, $ignore = false)
|
|
|
|
{
|
2021-03-08 22:36:30 +00:00
|
|
|
if (Folder::exists($dir))
|
2021-03-05 03:08:47 +00:00
|
|
|
{
|
|
|
|
$it = new RecursiveDirectoryIterator($dir);
|
|
|
|
$it = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST);
|
|
|
|
// remove ending /
|
|
|
|
$dir = rtrim($dir, '/');
|
|
|
|
// now loop the files & folders
|
|
|
|
foreach ($it as $file)
|
|
|
|
{
|
|
|
|
if ('.' === $file->getBasename() || '..' === $file->getBasename()) continue;
|
|
|
|
// set file dir
|
|
|
|
$file_dir = $file->getPathname();
|
|
|
|
// check if this is a dir or a file
|
|
|
|
if ($file->isDir())
|
|
|
|
{
|
|
|
|
$keeper = false;
|
|
|
|
if ($this->checkArray($ignore))
|
|
|
|
{
|
|
|
|
foreach ($ignore as $keep)
|
|
|
|
{
|
|
|
|
if (strpos($file_dir, $dir.'/'.$keep) !== false)
|
|
|
|
{
|
|
|
|
$keeper = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($keeper)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2021-03-08 22:36:30 +00:00
|
|
|
Folder::delete($file_dir);
|
2021-03-05 03:08:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$keeper = false;
|
|
|
|
if ($this->checkArray($ignore))
|
|
|
|
{
|
|
|
|
foreach ($ignore as $keep)
|
|
|
|
{
|
|
|
|
if (strpos($file_dir, $dir.'/'.$keep) !== false)
|
|
|
|
{
|
|
|
|
$keeper = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($keeper)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2021-03-08 22:36:30 +00:00
|
|
|
File::delete($file_dir);
|
2021-03-05 03:08:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// delete the root folder if not ignore found
|
|
|
|
if (!$this->checkArray($ignore))
|
|
|
|
{
|
2021-03-08 22:36:30 +00:00
|
|
|
return Folder::delete($dir);
|
2021-03-05 03:08:47 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
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-04-21 22:59:42 +00:00
|
|
|
}###INSTALLERMETHODS###
|
2021-03-05 03:08:47 +00:00
|
|
|
}
|