From 524b2d38bb5e50600a368f1900d9bc489634dc8e Mon Sep 17 00:00:00 2001 From: Michael Babker Date: Mon, 1 Sep 2014 11:32:19 -0400 Subject: [PATCH] Progrmatically insert the Uncategorised category --- .../language/en-GB/en-GB.com_weblinks.sys.ini | 1 + src/com_weblinks/admin/script.php | 71 +++++++++++++++++++ src/com_weblinks/admin/weblinks.xml | 6 +- 3 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 src/com_weblinks/admin/script.php diff --git a/src/com_weblinks/admin/language/en-GB/en-GB.com_weblinks.sys.ini b/src/com_weblinks/admin/language/en-GB/en-GB.com_weblinks.sys.ini index 915e886..2075385 100644 --- a/src/com_weblinks/admin/language/en-GB/en-GB.com_weblinks.sys.ini +++ b/src/com_weblinks/admin/language/en-GB/en-GB.com_weblinks.sys.ini @@ -15,6 +15,7 @@ COM_WEBLINKS_CATEGORY_VIEW_DEFAULT_TITLE="List Web Links in a Category" COM_WEBLINKS_CATEGORIES_VIEW_DEFAULT_DESC="Show all the web link categories within a category." COM_WEBLINKS_CATEGORIES_VIEW_DEFAULT_OPTION="Default" COM_WEBLINKS_CATEGORIES_VIEW_DEFAULT_TITLE="List All Web Link Categories" +COM_WEBLINKS_ERROR_INSTALL_CATEGORY="Could not add default 'Uncategorised' category due to an error: %s" COM_WEBLINKS_FORM_VIEW_DEFAULT_DESC="Display a form to submit a web link in the frontend." COM_WEBLINKS_FORM_VIEW_DEFAULT_OPTION="Default" COM_WEBLINKS_FORM_VIEW_DEFAULT_TITLE="Submit a Web Link" diff --git a/src/com_weblinks/admin/script.php b/src/com_weblinks/admin/script.php new file mode 100644 index 0000000..15e3527 --- /dev/null +++ b/src/com_weblinks/admin/script.php @@ -0,0 +1,71 @@ +load(array('extension' => 'com_weblinks', 'title' => 'Uncategorised'))) + { + $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->language = '*'; + + // Set the location in the tree + $category->setLocation(1, 'last-child'); + + // Check to make sure our data is valid + if (!$category->check()) + { + JFactory::getApplication()->enqueueMessage(JText::sprintf('COM_WEBLINKS_ERROR_INSTALL_CATEGORY', $category->getError())); + + return; + } + + // Now store the category + if (!$category->store(true)) + { + JFactory::getApplication()->enqueueMessage(JText::sprintf('COM_WEBLINKS_ERROR_INSTALL_CATEGORY', $category->getError())); + + return; + } + + // Build the path for our category + $category->rebuildPath($category->id); + } + } +} diff --git a/src/com_weblinks/admin/weblinks.xml b/src/com_weblinks/admin/weblinks.xml index b1005af..bbb7484 100644 --- a/src/com_weblinks/admin/weblinks.xml +++ b/src/com_weblinks/admin/weblinks.xml @@ -3,13 +3,13 @@ com_weblinks Joomla! Project April 2006 - (C) 2005 - 2014 Open Source Matters. All rights reserved. - + (C) 2005 - 2014 Open Source Matters. All rights reserved. GNU General Public License version 2 or later; see LICENSE.txt admin@joomla.org www.joomla.org 3.0.0 COM_WEBLINKS_XML_DESCRIPTION + script.php @@ -34,7 +34,6 @@ - index.html weblinks.php controller.php router.php @@ -63,7 +62,6 @@ access.xml config.xml controller.php - index.html weblinks.php controllers helpers