Skip to content

Commit

Permalink
Update Scriptfile
Browse files Browse the repository at this point in the history
  • Loading branch information
sonvnn committed Nov 25, 2024
1 parent a2b697e commit 51b0609
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 149 deletions.
2 changes: 1 addition & 1 deletion astroid.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<libraryname>astroid</libraryname>
<author>Astroid Framework Team</author>
<creationDate>November 2024</creationDate>
<version>3.1.8-rc1</version>
<version>3.1.8-rc2</version>
<url>https://astroidframe.work/</url>
<copyright>Copyright (C) 2024 TemPlaza, Inc. All rights reserved.</copyright>
<license>GNU General Public License version 3 or later; see LICENSE.txt</license>
Expand Down
4 changes: 2 additions & 2 deletions astroid_framework.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<updates>
<update>
<name>Astroid Framework</name>
<version>3.1.7</version>
<version>3.1.8</version>
<infourl title="Astroid Framework">https://astroidframe.work/</infourl>
<element>astroid</element>
<type>library</type>
<client>0</client>
<downloads>
<downloadurl type="full" format="zip">https://github.com/templaza/astroid-framework/releases/download/v3.1.7/astroid-framework-3.1.7.zip</downloadurl>
<downloadurl type="full" format="zip">https://github.com/templaza/astroid-framework/releases/download/v3.1.8/astroid-framework-3.1.8.zip</downloadurl>
</downloads>
<tags>
<tag>stable</tag>
Expand Down
2 changes: 1 addition & 1 deletion framework/library/astroid/Helper/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

class Constants
{
public static $astroid_version = '3.1.8-rc1';
public static $astroid_version = '3.1.8';
public static $fontawesome_version = '6.6.0';
public static $fancybox_version = '5.0';
public static $animatecss_version = '3.7.0';
Expand Down
329 changes: 184 additions & 145 deletions script.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,168 +3,207 @@
/**
* @package Astroid Framework
* @author Astroid Framework Team https://astroidframe.work
* @copyright Copyright (C) 2023 AstroidFrame.work
* @copyright Copyright (C) 2024 AstroidFrame.work
* @license https://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or Later
*/
use Joomla\CMS\Factory;
use Joomla\CMS\Installer\Installer;
use Astroid\Helper\Overrides;
use Joomla\Database\DatabaseInterface;

// no direct access
defined('_JEXEC') or die;
use Joomla\CMS\Application\AdministratorApplication;
use Joomla\CMS\Installer\InstallerAdapter;
use Joomla\CMS\Installer\InstallerScriptInterface;
use Joomla\CMS\Language\Text;
use Joomla\Database\DatabaseInterface;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Filesystem\File;
use Joomla\Filesystem\Exception\FilesystemException;
use Astroid\Helper\Overrides;
use Joomla\CMS\Installer\Installer;

if (!class_exists('astroidInstallerScript')) {
class astroidInstallerScript
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

return new class () implements ServiceProviderInterface {
public function register(Container $container)
{
/**
*
* Function to run before installing the component
*/
public function preflight($type, $parent)
{
$plugin_dir = JPATH_LIBRARIES . '/' . 'astroid' . '/' . 'plugins' . '/';
$plugins = array_filter(glob($plugin_dir . '*'), 'is_dir');
foreach ($plugins as $plugin) {
if ($type == "uninstall") {
$this->uninstallPlugin($plugin, $plugin_dir);
$container->set(
InstallerScriptInterface::class,
new class (
$container->get(AdministratorApplication::class),
$container->get(DatabaseInterface::class)
) implements InstallerScriptInterface {
private AdministratorApplication $app;
private DatabaseInterface $db;

public function __construct(AdministratorApplication $app, DatabaseInterface $db)
{
$this->app = $app;
$this->db = $db;
}

public function install(InstallerAdapter $parent): bool
{
$this->app->enqueueMessage('Successful installed.');

return true;
}
}

if (JVERSION >= 4) {
$module_dir = JPATH_LIBRARIES . '/' . 'astroid' . '/' . 'modules' . '/';
$modules = array_filter(glob($module_dir . '*'), 'is_dir');
foreach ($modules as $module) {
if ($type == "uninstall") {
$this->uninstallModule($module, $module_dir);
public function update(InstallerAdapter $parent): bool
{
$this->app->enqueueMessage('Successful updated.');

return true;
}

public function uninstall(InstallerAdapter $parent): bool
{
$this->app->enqueueMessage('Successful uninstalled.');

return true;
}

public function preflight(string $type, InstallerAdapter $parent): bool
{
$plugin_dir = JPATH_LIBRARIES . '/' . 'astroid' . '/' . 'plugins' . '/';
$plugins = array_filter(glob($plugin_dir . '*'), 'is_dir');
foreach ($plugins as $plugin) {
if ($type == "uninstall") {
$this->uninstallPlugin($plugin, $plugin_dir);
}
}

$module_dir = JPATH_LIBRARIES . '/' . 'astroid' . '/' . 'modules' . '/';
$modules = array_filter(glob($module_dir . '*'), 'is_dir');
foreach ($modules as $module) {
if ($type == "uninstall") {
$this->uninstallModule($module, $module_dir);
}
}
return true;
}
}
}

/**
*
* Function to run after installing the component
*/
public function postflight($type, $parent)
{
$plugin_dir = JPATH_LIBRARIES . '/' . 'astroid' . '/' . 'plugins' . '/';
$plugins = array_filter(glob($plugin_dir . '*'), 'is_dir');
foreach ($plugins as $plugin) {
if ($type == "install" || $type == "update") {
$this->installPlugin($plugin, $plugin_dir);

public function postflight(string $type, InstallerAdapter $parent): bool
{
$plugin_dir = JPATH_LIBRARIES . '/' . 'astroid' . '/' . 'plugins' . '/';
$plugins = array_filter(glob($plugin_dir . '*'), 'is_dir');
foreach ($plugins as $plugin) {
if ($type == "install" || $type == "update") {
$this->installPlugin($plugin, $plugin_dir);
}
}

$module_dir = JPATH_LIBRARIES . '/' . 'astroid' . '/' . 'modules' . '/';
$modules = array_filter(glob($module_dir . '*'), 'is_dir');
foreach ($modules as $module) {
if ($type == "install" || $type == "update") {
$this->installModule($module, $module_dir);
}
}

if ($type == "update") {
Overrides::fix();
}

return true;
}

private function installPlugin($plugin, $plugin_dir)
{
$db = $this->db;
$plugin_name = str_replace($plugin_dir, '', $plugin);

$installer = new Installer;
$installer->install($plugin);

$query = $db->getQuery(true);
$query->update('#__extensions');
$query->set($db->quoteName('enabled') . ' = 1');
$query->where($db->quoteName('element') . ' = ' . $db->quote($plugin_name));
$query->where($db->quoteName('type') . ' = ' . $db->quote('plugin'));
$db->setQuery($query);
$db->execute();
return true;
}
}

if (JVERSION >= 4) {
$module_dir = JPATH_LIBRARIES . '/' . 'astroid' . '/' . 'modules' . '/';
$modules = array_filter(glob($module_dir . '*'), 'is_dir');
foreach ($modules as $module) {
if ($type == "install" || $type == "update") {
$this->installModule($module, $module_dir);
private function installModule($module, $module_dir)
{
$db = $this->db;
$module_name = str_replace($module_dir, '', $module);

$installer = new Installer;
$installer->install($module);

$query = $db->getQuery(true);
$query->update('#__extensions');
$query->set($db->quoteName('enabled') . ' = 1');
$query->where($db->quoteName('element') . ' = ' . $db->quote($module_name));
$query->where($db->quoteName('type') . ' = ' . $db->quote('module'));
$db->setQuery($query);
$db->execute();

if ($module_name === 'mod_astroid_clear_cache') {
$query = $db->getQuery(true);
$query->update('#__modules');
$query->set($db->quoteName('published') . ' = 1');
$query->set($db->quoteName('position') . ' = ' . $db->quote('status'));
$query->set($db->quoteName('params') . ' = ' . $db->quote('{"layout":"_:default","moduleclass_sfx":"","style":"0","module_tag":"div","bootstrap_size":"0","header_tag":"h3","header_class":""}'));
$query->where($db->quoteName('module') . ' = ' . $db->quote($module_name));
$db->setQuery($query);
$db->execute();
}

// Retrieve ID
$query = $db->getQuery(true);
$query->select($db->quoteName('id'));
$query->from($db->quoteName('#__modules'));
$query->where($db->quoteName('module') . ' = ' . $db->quote($module_name));
$db->setQuery($query);
$id = (int) $db->loadResult();

if ($id) {
$query = $db->getQuery(true);
$query->select($db->quoteName('moduleid'));
$query->from($db->quoteName('#__modules_menu'));
$query->where($db->quoteName('moduleid') . ' = ' . $id);
$db->setQuery($query);
if (!$db->loadResult()) {
$db->getQuery(true);
$db->setQuery("INSERT INTO #__modules_menu (`moduleid`,`menuid`) VALUES (".$id.", 0)");
$db->execute();
}
}
return true;
}
}

if ($type == "update") {
Overrides::fix();
}
}

public function installPlugin($plugin, $plugin_dir)
{
$db = Factory::getContainer()->get(DatabaseInterface::class);
$plugin_name = str_replace($plugin_dir, '', $plugin);

$installer = new Installer;
$installer->install($plugin);

$query = $db->getQuery(true);
$query->update('#__extensions');
$query->set($db->quoteName('enabled') . ' = 1');
$query->where($db->quoteName('element') . ' = ' . $db->quote($plugin_name));
$query->where($db->quoteName('type') . ' = ' . $db->quote('plugin'));
$db->setQuery($query);
$db->execute();
return true;
}

public function installModule($module, $module_dir)
{
$db = Factory::getContainer()->get(DatabaseInterface::class);
$module_name = str_replace($module_dir, '', $module);

$installer = new Installer;
$installer->install($module);

$query = $db->getQuery(true);
$query->update('#__extensions');
$query->set($db->quoteName('enabled') . ' = 1');
$query->where($db->quoteName('element') . ' = ' . $db->quote($module_name));
$query->where($db->quoteName('type') . ' = ' . $db->quote('module'));
$db->setQuery($query);
$db->execute();

if ($module_name === 'mod_astroid_clear_cache') {
$query = $db->getQuery(true);
$query->update('#__modules');
$query->set($db->quoteName('published') . ' = 1');
$query->set($db->quoteName('position') . ' = ' . $db->quote('status'));
$query->set($db->quoteName('params') . ' = ' . $db->quote('{"layout":"_:default","moduleclass_sfx":"","style":"0","module_tag":"div","bootstrap_size":"0","header_tag":"h3","header_class":""}'));
$query->where($db->quoteName('module') . ' = ' . $db->quote($module_name));
$db->setQuery($query);
$db->execute();
}
private function uninstallPlugin($plugin, $plugin_dir)
{
$db = $this->db;
$plugin_name = str_replace($plugin_dir, '', $plugin);
$query = $db->getQuery(true);
$query->update('#__extensions');
$query->set($db->quoteName('enabled') . ' = 0');
$query->where($db->quoteName('element') . ' = ' . $db->quote($plugin_name));
$query->where($db->quoteName('type') . ' = ' . $db->quote('plugin'));
$db->setQuery($query);
$db->execute();
return true;
}

// Retrieve ID
$query = $db->getQuery(true);
$query->select($db->quoteName('id'));
$query->from($db->quoteName('#__modules'));
$query->where($db->quoteName('module') . ' = ' . $db->quote($module_name));
$db->setQuery($query);
$id = (int) $db->loadResult();

if ($id) {
$query = $db->getQuery(true);
$query->select($db->quoteName('moduleid'));
$query->from($db->quoteName('#__modules_menu'));
$query->where($db->quoteName('moduleid') . ' = ' . $id);
$db->setQuery($query);
if (!$db->loadResult()) {
$db->getQuery(true);
$db->setQuery("INSERT INTO #__modules_menu (`moduleid`,`menuid`) VALUES (".$id.", 0)");
private function uninstallModule($module, $module_dir)
{
$db = $this->db;
$module_name = str_replace($module_dir, '', $module);
$query = $db->getQuery(true);
$query->update('#__extensions');
$query->set($db->quoteName('enabled') . ' = 0');
$query->where($db->quoteName('element') . ' = ' . $db->quote($module_name));
$query->where($db->quoteName('type') . ' = ' . $db->quote('module'));
$db->setQuery($query);
$db->execute();
return true;
}
}
return true;
}

public function uninstallPlugin($plugin, $plugin_dir)
{
$db = Factory::getContainer()->get(DatabaseInterface::class);
$plugin_name = str_replace($plugin_dir, '', $plugin);
$query = $db->getQuery(true);
$query->update('#__extensions');
$query->set($db->quoteName('enabled') . ' = 0');
$query->where($db->quoteName('element') . ' = ' . $db->quote($plugin_name));
$query->where($db->quoteName('type') . ' = ' . $db->quote('plugin'));
$db->setQuery($query);
$db->execute();
return true;
}

public function uninstallModule($module, $module_dir)
{
$db = Factory::getContainer()->get(DatabaseInterface::class);
$module_name = str_replace($module_dir, '', $module);
$query = $db->getQuery(true);
$query->update('#__extensions');
$query->set($db->quoteName('enabled') . ' = 0');
$query->where($db->quoteName('element') . ' = ' . $db->quote($module_name));
$query->where($db->quoteName('type') . ' = ' . $db->quote('module'));
$db->setQuery($query);
$db->execute();
return true;
}
);
}
}
};

0 comments on commit 51b0609

Please sign in to comment.