Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
/.idea/inspectionProfiles/Project_Default.xml
/.idea/vcs.xml
/administrator/com_joomgallery/joomgallery.xml
/administrator/com_joomgallery/joomgallery_old.xml
node_modules
12 changes: 12 additions & 0 deletions administrator/com_joomgallery/src/Table/CategoryTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,18 @@ public function getTypeAlias()
return $this->typeAlias;
}

/**
* Resets the root_id property to the default value: 0
*
* @return void
*
* @since 4.0.0
*/
public static function resetRootId()
{
self::$root_id = 0;
}

/**
* Define a namespaced asset name for inclusion in the #__assets table
*
Expand Down
100 changes: 70 additions & 30 deletions script.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@
defined('_JEXEC') or die();

use \Joomla\CMS\Factory;
use \Joomla\Database\DatabaseInterface;
use \Joomla\CMS\Uri\Uri;
use \Joomla\CMS\Table\Table;
use \Joomla\CMS\Language\Text;
use \Joomla\CMS\Router\Route;
use \Joomla\CMS\Installer\Installer;
use \Joomla\CMS\Installer\InstallerScript;
use \Joomla\CMS\Filesystem\File;
use \Joomla\CMS\Filesystem\Folder;
use \Joomla\CMS\Uri\Uri;
use \Joomla\CMS\Table\Table;
use \Joomla\CMS\Installer\Installer;
use \Joomla\CMS\Installer\InstallerScript;
use \Joomla\Database\DatabaseInterface;
use \Joomla\CMS\Language\LanguageFactoryInterface;

/**
* Install method
Expand Down Expand Up @@ -58,13 +59,28 @@ class com_joomgalleryInstallerScript extends InstallerScript
*/
protected $new_code = '';

/**
* Counter variable
*
* @var int
*/
protected $count = 0;

/**
* True to skip output during install() method
*
* @var bool
*/
protected $installSkipMsg = false;

/**
* True to show that the current script is exectuted during an upgrade
* from an old JoomGallery version (JG 1-3)
*
* @var bool
*/
protected $fromOldJG = false;


/**
* Method called before install/update the component. Note: This method won't be called during uninstall process.
Expand Down Expand Up @@ -141,13 +157,19 @@ public function preflight($type, $parent)
if($jgtables)
{
$db = Factory::getContainer()->get(DatabaseInterface::class);

foreach($jgtables as $oldTable)
{
$db->renameTable($oldTable, $oldTable.'_old');
}
}

// copy old XML file (JGv1-3)
$xml_path = JPATH_ADMINISTRATOR.DIRECTORY_SEPARATOR.'components'.DIRECTORY_SEPARATOR.'com_joomgallery'.DIRECTORY_SEPARATOR;
if(File::exists($xml_path.'joomgallery.xml'))
{
File::copy($xml_path.'joomgallery.xml', $xml_path.'joomgallery_old.xml');
}

// remove old JoomGallery files and folders
foreach($this->detectJGfolders() as $folder)
{
Expand Down Expand Up @@ -208,12 +230,14 @@ public function install($parent)

if($this->installSkipMsg)
{
// Skip install method here if we upgrade from an old version
// and we don't want to show the install text.
return;
}

// Create news feed module
$subdomain = '';
$language = Factory::getLanguage();
$language = $app->getLanguage();
if(strpos($language->getTag(), 'de-') === false)
{
$subdomain = 'en.';
Expand Down Expand Up @@ -269,6 +293,7 @@ public function update($parent)
{
// We update from an old version (JG 1-3)
$this->installSkipMsg = true;
$this->fromOldJG = true;
$this->install($parent);
}
else
Expand Down Expand Up @@ -388,7 +413,7 @@ public function uninstall($parent)
*/
function postflight($type, $parent)
{
if($type == 'install')
if($type == 'install' || ($type == 'update' && $this->fromOldJG))
{
$app = Factory::getApplication();

Expand Down Expand Up @@ -520,7 +545,8 @@ public function addDefaultCategory()
require_once $class_path;

if(class_exists($tableClass))
{
{
$tableClass::resetRootId();
$table = new $tableClass($db);
}
else
Expand Down Expand Up @@ -854,35 +880,47 @@ private function installModules($parent)
/**
* Uninstalls plugins
*
* @param mixed $parent Object who called the uninstall method
* @param mixed $parent Object who called the uninstall method or array with plugin names
*
* @return void
* @return void
*/
private function uninstallPlugins($parent)
{
$app = Factory::getApplication();

if(method_exists($parent, 'getManifest'))
{
$plugins = $parent->getManifest()->plugins;
}
else
{
$plugins = $parent->get('manifest')->plugins;
}

if(!$plugins || empty($plugins->children()) || count($plugins->children()) <= 0)
if(is_array($parent))
{
return;
// We got an array of module names
$modules = $parent;
}
else
{
// We got the parent object
if(method_exists($parent, 'getManifest'))
{
$plugins = $parent->getManifest()->plugins;
}
else
{
$plugins = $parent->get('manifest')->plugins;
}

if(!$plugins || empty($plugins->children()) || count($plugins->children()) <= 0)
{
return;
}

$plugins = $plugins->children();
}

$db = Factory::getContainer()->get(DatabaseInterface::class);
$query = $db->getQuery(true);

foreach($plugins->children() as $plugin)
foreach($plugins as $plugin)
{
$pluginName = (string) $plugin['plugin'];
$pluginGroup = (string) $plugin['group'];

$query
->clear()
->select('extension_id')
Expand Down Expand Up @@ -941,17 +979,19 @@ private function uninstallModules($parent)
{
$modules = $parent->get('manifest')->modules;
}
}

if(!$modules || empty($modules->children()) || count($modules->children()) <= 0)
{
return;
}
if(!$modules || empty($modules->children()) || count($modules->children()) <= 0)
{
return;
}

$modules = $modules->children();
}

$db = Factory::getContainer()->get(DatabaseInterface::class);
$query = $db->getQuery(true);

foreach($modules->children() as $module)
foreach($modules as $module)
{
if(is_array($parent))
{
Expand Down Expand Up @@ -1300,7 +1340,7 @@ private function createModule($title, $position, $module, $ordering, $access, $s
$row->language = $lang;
if(!$row->store())
{
$app->enqueueMessage(Text::_('Unable to create "'.$title.'" module!'), 'error');
Factory::getApplication()->enqueueMessage(Text::_('Unable to create "'.$title.'" module!'), 'error');

return false;
}
Expand Down