Last active
August 29, 2015 13:56
-
-
Save renekreijveld/8823046 to your computer and use it in GitHub Desktop.
Example CLI script for Joomla 2.5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @package Joomla.Cli | |
* | |
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved. | |
* @license GNU General Public License version 2 or later; see LICENSE.txt | |
* | |
* Joomla 2.5 example CLI script | |
* Written by: Rene Kreijveld, email [at] renekreijveld.nl | |
* 05-feb-2014 | |
* Put this script in the /cli folder in the root of your Joomla 2.5 website | |
* Execute by php <path_to_your_joomla_root>/cli/clidemo_2.5.php | |
*/ | |
// Set flag that this is a parent file. | |
define('_JEXEC', 1); | |
error_reporting(E_ALL | E_NOTICE); | |
ini_set('display_errors', 1); | |
// Load system defines | |
if (file_exists(dirname(__DIR__) . '/defines.php')) | |
{ | |
require_once dirname(__DIR__) . '/defines.php'; | |
} | |
if (!defined('_JDEFINES')) | |
{ | |
define('JPATH_BASE', dirname(__DIR__)); | |
require_once JPATH_BASE . '/includes/defines.php'; | |
} | |
require_once JPATH_LIBRARIES . '/import.php'; | |
require_once JPATH_LIBRARIES . '/cms.php'; | |
// Force library to be in JError legacy mode | |
JError::$legacy = true; | |
/** | |
* This script will fetch the update information for all extensions and store | |
* them in the database, speeding up your administrator. | |
* | |
* @package Joomla.CLI | |
* @since 2.5 | |
*/ | |
class Clidemo extends JApplicationCli | |
{ | |
/** | |
* Entry point for the script | |
* | |
* @return void | |
* | |
* @since 2.5 | |
*/ | |
public function doExecute() | |
{ | |
// Database connector | |
$db = JFactory::getDBO(); | |
$this->out('Setting query'); | |
// Set SQL query | |
$query = "SELECT COUNT(*) from #__users"; | |
// Execute query | |
$db->setQuery($query); | |
// Get result | |
$number_of_users = $db->loadResult(); | |
$this->out('Query done'); | |
// Output result | |
$this->out("We found $number_of_users users."); | |
} | |
} | |
JApplicationCli::getInstance('Clidemo')->execute(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment