2015-05-18 00:49:59 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2016-12-01 07:21:47 +00:00
|
|
|
* @package Joomla.Administrator
|
|
|
|
* @subpackage Weblinks
|
2015-05-18 00:49:59 +00:00
|
|
|
*
|
2017-02-13 16:20:35 +00:00
|
|
|
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
|
2015-05-18 00:49:59 +00:00
|
|
|
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
defined('_JEXEC') or die;
|
|
|
|
|
2021-07-01 14:46:35 +00:00
|
|
|
use Joomla\CMS\Factory;
|
2021-07-10 11:23:14 +00:00
|
|
|
use Joomla\CMS\Filesystem\File;
|
|
|
|
use Joomla\CMS\Filesystem\Folder;
|
|
|
|
use Joomla\CMS\Installer\InstallerAdapter;
|
2021-07-09 09:42:45 +00:00
|
|
|
use Joomla\CMS\Language\Text;
|
2021-07-10 11:23:14 +00:00
|
|
|
use Joomla\CMS\Table\Table;
|
2021-07-01 14:41:54 +00:00
|
|
|
|
2015-05-18 00:49:59 +00:00
|
|
|
/**
|
|
|
|
* Installation class to perform additional changes during install/uninstall/update
|
|
|
|
*
|
2015-05-18 18:34:08 +00:00
|
|
|
* @since 3.4
|
2015-05-18 00:49:59 +00:00
|
|
|
*/
|
|
|
|
class Com_WeblinksInstallerScript
|
|
|
|
{
|
2021-07-10 11:23:14 +00:00
|
|
|
/**
|
|
|
|
* Function called before extension installation/update/removal procedure commences
|
|
|
|
*
|
|
|
|
* @param string $type The type of change (install, update or discover_install, not uninstall)
|
|
|
|
* @param InstallerAdapter $parent The class calling this method
|
|
|
|
*
|
|
|
|
* @return boolean True on success
|
|
|
|
*
|
|
|
|
* @since 4.0
|
|
|
|
*/
|
|
|
|
public function preflight($type, $parent)
|
|
|
|
{
|
|
|
|
$files = [
|
|
|
|
'/administrator/components/com_weblinks/controller.php',
|
|
|
|
'/administrator/components/com_weblinks/weblinks.php',
|
|
|
|
'/administrator/components/com_weblinks/helpers/associations.php',
|
|
|
|
'/administrator/components/com_weblinks/sql/install.sqlsrv.sql',
|
|
|
|
'/administrator/components/com_weblinks/sql/uninstall.sqlsrv.sql',
|
|
|
|
'/components/com_weblinks/helpers/association.php',
|
|
|
|
'/components/com_weblinks/helpers/category.php',
|
|
|
|
'/components/com_weblinks/controller.php',
|
|
|
|
'/components/com_weblinks/weblinks.php',
|
|
|
|
'/components/com_weblinks/metadata.xml',
|
|
|
|
'/components/com_weblinks/router.php',
|
|
|
|
];
|
|
|
|
|
|
|
|
$folders = [
|
|
|
|
'/administrator/components/com_weblinks/controllers',
|
|
|
|
'/administrator/components/com_weblinks/helpers/html',
|
|
|
|
'/administrator/components/com_weblinks/models',
|
|
|
|
'/administrator/components/com_weblinks/sql/updates/sqlsrv',
|
|
|
|
'/administrator/components/com_weblinks/tables',
|
|
|
|
'/administrator/components/com_weblinks/views',
|
|
|
|
'/components/com_weblinks/controllers',
|
|
|
|
'/administrator/components/com_weblinks/models',
|
|
|
|
'/administrator/components/com_weblinks/views',
|
|
|
|
];
|
|
|
|
|
|
|
|
foreach ($files as $file)
|
|
|
|
{
|
|
|
|
if (File::exists(JPATH_ROOT . $file))
|
|
|
|
{
|
|
|
|
File::delete(JPATH_ROOT . $file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($folders as $folder)
|
|
|
|
{
|
|
|
|
if (Folder::exists(JPATH_ROOT . $folder))
|
|
|
|
{
|
|
|
|
Folder::delete(JPATH_ROOT . $folder);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-05-18 00:49:59 +00:00
|
|
|
/**
|
|
|
|
* Function to perform changes during install
|
|
|
|
*
|
|
|
|
* @param JInstallerAdapterComponent $parent The class calling this method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*
|
|
|
|
* @since 3.4
|
|
|
|
*/
|
|
|
|
public function install($parent)
|
|
|
|
{
|
|
|
|
// Initialize a new category
|
2021-07-18 11:39:55 +00:00
|
|
|
/** @type Joomla\CMS\Table\Category $category */
|
|
|
|
$category = Table::getInstance('Category', 'Joomla\\CMS\\Table\\');
|
2015-05-18 00:49:59 +00:00
|
|
|
|
|
|
|
// Check if the Uncategorised category exists before adding it
|
|
|
|
if (!$category->load(array('extension' => 'com_weblinks', 'title' => 'Uncategorised')))
|
|
|
|
{
|
2021-07-17 15:43:08 +00:00
|
|
|
$category->extension = 'com_weblinks';
|
|
|
|
$category->title = 'Uncategorised';
|
|
|
|
$category->description = '';
|
|
|
|
$category->published = 1;
|
|
|
|
$category->access = 1;
|
|
|
|
$category->params = '{"category_layout":"","image":""}';
|
|
|
|
$category->metadata = '{"author":"","robots":""}';
|
|
|
|
$category->metadesc = '';
|
|
|
|
$category->metakey = '';
|
|
|
|
$category->language = '*';
|
2021-07-01 14:46:35 +00:00
|
|
|
$category->checked_out_time = Factory::getDbo()->getNullDate();
|
2021-07-17 15:43:08 +00:00
|
|
|
$category->version = 1;
|
|
|
|
$category->hits = 0;
|
2015-09-08 09:59:05 +00:00
|
|
|
$category->modified_user_id = 0;
|
2021-07-17 15:43:08 +00:00
|
|
|
$category->checked_out = 0;
|
2015-05-18 00:49:59 +00:00
|
|
|
|
|
|
|
// Set the location in the tree
|
|
|
|
$category->setLocation(1, 'last-child');
|
|
|
|
|
|
|
|
// Check to make sure our data is valid
|
|
|
|
if (!$category->check())
|
|
|
|
{
|
2021-07-01 14:46:35 +00:00
|
|
|
Factory::getApplication()->enqueueMessage(Text::sprintf('COM_WEBLINKS_ERROR_INSTALL_CATEGORY', $category->getError()));
|
2015-05-18 00:49:59 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now store the category
|
|
|
|
if (!$category->store(true))
|
|
|
|
{
|
2021-07-01 14:46:35 +00:00
|
|
|
Factory::getApplication()->enqueueMessage(Text::sprintf('COM_WEBLINKS_ERROR_INSTALL_CATEGORY', $category->getError()));
|
2015-05-18 00:49:59 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build the path for our category
|
|
|
|
$category->rebuildPath($category->id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-05-18 18:34:08 +00:00
|
|
|
* Method to run after the install routine.
|
2015-05-18 00:49:59 +00:00
|
|
|
*
|
2015-05-18 18:34:08 +00:00
|
|
|
* @param string $type The action being performed
|
|
|
|
* @param JInstallerAdapterComponent $parent The class calling this method
|
|
|
|
*
|
|
|
|
* @return void
|
2015-05-18 00:49:59 +00:00
|
|
|
*
|
2015-05-18 18:34:08 +00:00
|
|
|
* @since 3.4.1
|
2015-05-18 00:49:59 +00:00
|
|
|
*/
|
2015-05-18 18:34:08 +00:00
|
|
|
public function postflight($type, $parent)
|
2015-05-18 00:49:59 +00:00
|
|
|
{
|
2015-05-18 18:34:08 +00:00
|
|
|
// Only execute database changes on MySQL databases
|
2021-07-01 14:46:35 +00:00
|
|
|
$dbName = Factory::getDbo()->name;
|
2015-05-18 18:34:08 +00:00
|
|
|
|
|
|
|
if (strpos($dbName, 'mysql') !== false)
|
|
|
|
{
|
2021-07-18 11:23:35 +00:00
|
|
|
// Add Missing Table Columns if needed
|
2015-05-19 11:55:01 +00:00
|
|
|
$this->addColumnsIfNeeded();
|
|
|
|
|
2021-07-18 11:23:35 +00:00
|
|
|
// Drop the Table Columns if needed
|
2015-05-18 18:34:08 +00:00
|
|
|
$this->dropColumnsIfNeeded();
|
|
|
|
}
|
2015-05-18 00:49:59 +00:00
|
|
|
|
|
|
|
// Insert missing UCM Records if needed
|
|
|
|
$this->insertMissingUcmRecords();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method to insert missing records for the UCM tables
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*
|
|
|
|
* @since 3.4.1
|
|
|
|
*/
|
2015-05-18 18:34:08 +00:00
|
|
|
private function insertMissingUcmRecords()
|
2015-05-18 00:49:59 +00:00
|
|
|
{
|
|
|
|
// Insert the rows in the #__content_types table if they don't exist already
|
2021-07-01 14:46:35 +00:00
|
|
|
$db = Factory::getDbo();
|
2015-05-18 00:49:59 +00:00
|
|
|
|
|
|
|
// Get the type ID for a Weblink
|
|
|
|
$query = $db->getQuery(true);
|
2015-05-18 13:42:13 +00:00
|
|
|
$query->select($db->quoteName('type_id'))
|
|
|
|
->from($db->quoteName('#__content_types'))
|
2015-05-18 13:42:33 +00:00
|
|
|
->where($db->quoteName('type_alias') . ' = ' . $db->quote('com_weblinks.weblink'));
|
2015-05-18 00:49:59 +00:00
|
|
|
$db->setQuery($query);
|
|
|
|
|
|
|
|
$weblinkTypeId = $db->loadResult();
|
|
|
|
|
|
|
|
// Get the type ID for a Weblink Category
|
|
|
|
$query->clear('where');
|
|
|
|
$query->where($db->quoteName('type_alias') . ' = ' . $db->quote('com_weblinks.category'));
|
|
|
|
$db->setQuery($query);
|
|
|
|
|
|
|
|
$categoryTypeId = $db->loadResult();
|
|
|
|
|
|
|
|
// Set the table columns to insert table to
|
|
|
|
$columnsArray = array(
|
|
|
|
$db->quoteName('type_title'),
|
|
|
|
$db->quoteName('type_alias'),
|
|
|
|
$db->quoteName('table'),
|
|
|
|
$db->quoteName('rules'),
|
|
|
|
$db->quoteName('field_mappings'),
|
|
|
|
$db->quoteName('router'),
|
|
|
|
$db->quoteName('content_history_options'),
|
|
|
|
);
|
|
|
|
|
|
|
|
// If we have no type id for com_weblinks.weblink insert it
|
|
|
|
if (!$weblinkTypeId)
|
|
|
|
{
|
|
|
|
// Insert the data.
|
|
|
|
$query->clear();
|
|
|
|
$query->insert($db->quoteName('#__content_types'));
|
|
|
|
$query->columns($columnsArray);
|
|
|
|
$query->values(
|
|
|
|
$db->quote('Weblink') . ', '
|
|
|
|
. $db->quote('com_weblinks.weblink') . ', '
|
2016-06-28 21:08:56 +00:00
|
|
|
. $db->quote(
|
|
|
|
'{"special":{"dbtable":"#__weblinks","key":"id","type":"Weblink","prefix":"WeblinksTable","config":"array()"},
|
2021-06-26 10:13:37 +00:00
|
|
|
"common":{"dbtable":"#__ucm_content","key":"ucm_id","type":"Corecontent","prefix":"JTable","config":"array()"}}'
|
|
|
|
) . ', '
|
2015-05-18 00:49:59 +00:00
|
|
|
. $db->quote('') . ', '
|
2016-06-28 21:08:56 +00:00
|
|
|
. $db->quote(
|
|
|
|
'{"common":{"core_content_item_id":"id","core_title":"title","core_state":"state","core_alias":"alias",
|
|
|
|
"core_created_time":"created","core_modified_time":"modified","core_body":"description", "core_hits":"hits",
|
|
|
|
"core_publish_up":"publish_up","core_publish_down":"publish_down","core_access":"access", "core_params":"params",
|
|
|
|
"core_featured":"featured", "core_metadata":"metadata", "core_language":"language", "core_images":"images", "core_urls":"url",
|
|
|
|
"core_version":"version", "core_ordering":"ordering", "core_metakey":"metakey", "core_metadesc":"metadesc",
|
2021-06-26 10:13:37 +00:00
|
|
|
"core_catid":"catid", "core_xreference":"xreference", "asset_id":"null"}, "special":{}}'
|
|
|
|
) . ', '
|
2015-05-18 00:49:59 +00:00
|
|
|
. $db->quote('WeblinksHelperRoute::getWeblinkRoute') . ', '
|
2016-06-28 21:08:56 +00:00
|
|
|
. $db->quote(
|
|
|
|
'{"formFile":"administrator\\/components\\/com_weblinks\\/models\\/forms\\/weblink.xml",
|
|
|
|
"hideFields":["asset_id","checked_out","checked_out_time","version","featured","images"], "ignoreChanges":["modified_by",
|
|
|
|
"modified", "checked_out", "checked_out_time", "version", "hits"], "convertToInt":["publish_up", "publish_down", "featured",
|
|
|
|
"ordering"], "displayLookup":[{"sourceColumn":"catid","targetTable":"#__categories","targetColumn":"id","displayColumn":"title"},
|
|
|
|
{"sourceColumn":"created_by","targetTable":"#__users","targetColumn":"id","displayColumn":"name"},
|
|
|
|
{"sourceColumn":"access","targetTable":"#__viewlevels","targetColumn":"id","displayColumn":"title"},
|
2021-06-26 10:13:37 +00:00
|
|
|
{"sourceColumn":"modified_by","targetTable":"#__users","targetColumn":"id","displayColumn":"name"} ]}'
|
|
|
|
)
|
2015-05-18 00:49:59 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$db->setQuery($query);
|
|
|
|
$db->execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we have no type id for com_weblinks.category insert it
|
|
|
|
if (!$categoryTypeId)
|
|
|
|
{
|
|
|
|
// Insert the data.
|
|
|
|
$query->clear();
|
|
|
|
$query->insert($db->quoteName('#__content_types'));
|
|
|
|
$query->columns($columnsArray);
|
|
|
|
$query->values(
|
|
|
|
$db->quote('Weblinks Category') . ', '
|
|
|
|
. $db->quote('com_weblinks.category') . ', '
|
2016-06-28 21:08:56 +00:00
|
|
|
. $db->quote('
|
|
|
|
{"special":{"dbtable":"#__categories","key":"id","type":"Category","prefix":"JTable","config":"array()"},
|
2021-06-26 10:13:37 +00:00
|
|
|
"common":{"dbtable":"#__ucm_content","key":"ucm_id","type":"Corecontent","prefix":"JTable","config":"array()"}}'
|
|
|
|
) . ', '
|
2015-05-18 00:49:59 +00:00
|
|
|
. $db->quote('') . ', '
|
2016-06-28 21:08:56 +00:00
|
|
|
. $db->quote('
|
|
|
|
{"common":{"core_content_item_id":"id","core_title":"title","core_state":"published","core_alias":"alias",
|
|
|
|
"core_created_time":"created_time","core_modified_time":"modified_time","core_body":"description",
|
|
|
|
"core_hits":"hits","core_publish_up":"null","core_publish_down":"null","core_access":"access",
|
|
|
|
"core_params":"params", "core_featured":"null", "core_metadata":"metadata", "core_language":"language",
|
|
|
|
"core_images":"null", "core_urls":"null", "core_version":"version", "core_ordering":"null", "core_metakey":"metakey",
|
|
|
|
"core_metadesc":"metadesc", "core_catid":"parent_id", "core_xreference":"null", "asset_id":"asset_id"},
|
2021-06-26 10:13:37 +00:00
|
|
|
"special":{"parent_id":"parent_id","lft":"lft","rgt":"rgt","level":"level","path":"path","extension":"extension","note":"note"}}'
|
|
|
|
) . ', '
|
2015-05-18 00:49:59 +00:00
|
|
|
. $db->quote('WeblinksHelperRoute::getCategoryRoute') . ', '
|
2016-06-28 21:08:56 +00:00
|
|
|
. $db->quote('
|
|
|
|
{"formFile":"administrator\\/components\\/com_categories\\/models\\/forms\\/category.xml",
|
|
|
|
"hideFields":["asset_id","checked_out","checked_out_time","version","lft","rgt","level","path","extension"],
|
|
|
|
"ignoreChanges":["modified_user_id", "modified_time", "checked_out", "checked_out_time", "version",
|
|
|
|
"hits", "path"],"convertToInt":["publish_up", "publish_down"],
|
|
|
|
"displayLookup":[{"sourceColumn":"created_user_id","targetTable":"#__users","targetColumn":"id",
|
|
|
|
"displayColumn":"name"},{"sourceColumn":"access","targetTable":"#__viewlevels","targetColumn":"id",
|
|
|
|
"displayColumn":"title"},{"sourceColumn":"modified_user_id","targetTable":"#__users","targetColumn":"id",
|
|
|
|
"displayColumn":"name"},{"sourceColumn":"parent_id","targetTable":"#__categories","targetColumn":"id",
|
2021-06-26 10:13:37 +00:00
|
|
|
"displayColumn":"title"}]}'
|
|
|
|
)
|
2015-05-18 00:49:59 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$db->setQuery($query);
|
|
|
|
$db->execute();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method to drop colums from #__weblinks if they still there.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*
|
|
|
|
* @since 3.4.1
|
|
|
|
*/
|
|
|
|
private function dropColumnsIfNeeded()
|
|
|
|
{
|
|
|
|
$oldColumns = array(
|
|
|
|
'sid',
|
|
|
|
'date',
|
|
|
|
'archived',
|
|
|
|
'approved',
|
|
|
|
);
|
|
|
|
|
2021-07-01 14:46:35 +00:00
|
|
|
$db = Factory::getDbo();
|
2015-05-18 00:49:59 +00:00
|
|
|
$table = $db->getTableColumns('#__weblinks');
|
|
|
|
|
|
|
|
$columns = array_intersect($oldColumns, array_keys($table));
|
|
|
|
|
|
|
|
foreach ($columns as $column)
|
|
|
|
{
|
2015-05-18 18:34:08 +00:00
|
|
|
$sql = 'ALTER TABLE ' . $db->quoteName('#__weblinks') . ' DROP COLUMN ' . $db->quoteName($column);
|
2015-05-18 00:49:59 +00:00
|
|
|
$db->setQuery($sql);
|
|
|
|
$db->execute();
|
|
|
|
}
|
|
|
|
}
|
2015-05-19 11:55:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Method to add colums from #__weblinks if they are missing.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*
|
|
|
|
* @since 3.4.1
|
|
|
|
*/
|
|
|
|
private function addColumnsIfNeeded()
|
|
|
|
{
|
2021-07-01 14:46:35 +00:00
|
|
|
$db = Factory::getDbo();
|
2015-05-19 11:55:01 +00:00
|
|
|
$table = $db->getTableColumns('#__weblinks');
|
|
|
|
|
|
|
|
if (!array_key_exists('version', $table))
|
|
|
|
{
|
2021-08-15 10:39:00 +00:00
|
|
|
$sql = 'ALTER TABLE ' . $db->quoteName('#__weblinks') . ' ADD COLUMN ' . $db->quoteName('version') . " int unsigned NOT NULL DEFAULT '1'";
|
2015-05-19 11:55:01 +00:00
|
|
|
$db->setQuery($sql);
|
|
|
|
$db->execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!array_key_exists('images', $table))
|
|
|
|
{
|
|
|
|
$sql = 'ALTER TABLE ' . $db->quoteName('#__weblinks') . ' ADD COLUMN ' . $db->quoteName('images') . ' text NOT NULL';
|
|
|
|
$db->setQuery($sql);
|
|
|
|
$db->execute();
|
|
|
|
}
|
|
|
|
}
|
2021-07-17 15:43:08 +00:00
|
|
|
}
|