I'm migrating a Joomla 1.7 site to use Joomla 2.5. The prior developers did a lot of regrettable things, one of which was to create a nightly cron job that ran dozens of queries directly on the Joomla db using mysql_query.
I'm hoping to modify the database access in this cron job such that is uses the Joomla classes and credentials to access the database rather than having a separate database connect/query structure unto itself. In particular:
* db credentials in configuration.php
* JDatabase object (and any related exceptions or other classes)
Is there some standardized way to do this?
Please note that:
* I do not want this script to live in the web root, lest someone set it off by accessing the script in a web browser
* I don't expect to create a component/module/plugin here and am hoping to avoid any additional overhead required by these more formalized concepts.
* ideally whatever technique I use will be forward-compatible with Joomla 3, etc. so that we don't face another rewrite when we upgrade again.
* I don't want to modify any of the Joomla code so that my project cannot be easily upgraded -- i.e., I don't want to alter any files to break compatibility with Joomla.
Any help you could provide would be much appreciated. I very much want to get this done quickly and am currently looking at around 60 queries that must be adapted (and quickly!) -- I don't want to have to fix them again in the future.
Need to use Joomla database credentials/objs in a cron job
Moderator: General Support Moderators
Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting.
Forum Post Assistant - If you are serious about wanting help, you should use this tool to help you post.
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting.
Forum Post Assistant - If you are serious about wanting help, you should use this tool to help you post.
-
- Joomla! Intern
- Posts: 70
- Joined: Mon Jun 21, 2010 12:26 am
Need to use Joomla database credentials/objs in a cron job
make multiplayer flash games: http://flashmog.net
- alikon
- Joomla! Champion
- Posts: 5941
- Joined: Fri Aug 19, 2005 10:46 am
- Location: Roma
- Contact:
Re: Need to use Joomla database credentials/objs in a cron j
https://github.com/joomla/joomla-platfo ... i/database
an example on how to work with db from a joomla platform CLI
an example on how to work with db from a joomla platform CLI
-
- Joomla! Intern
- Posts: 70
- Joined: Mon Jun 21, 2010 12:26 am
Re: Need to use Joomla database credentials/objs in a cron j
I appreciate the suggestion, but have noticed a variety of problems:alikon wrote:https://github.com/joomla/joomla-platfo ... i/database
an example on how to work with db from a joomla platform CLI
1) The file configuration.php defines different members than the one in my Joomla project. E.g., my JConfig class has class var $db while theirs has $dbName, etc.
2) The file run.php includes a file boostrap.php. The example they have refers to a joomla-platform project and I can't determine whether this refers to my Joomla 2.5 install or whether this is some separate library I must download from github.
Can you explain a bit more to me about this thing you have suggested? What version of Joomla is it for? Is it a distinct library that must be downloaded?
make multiplayer flash games: http://flashmog.net
-
- Joomla! Intern
- Posts: 70
- Joined: Mon Jun 21, 2010 12:26 am
Re: Need to use Joomla database credentials/objs in a cron j
I'm also having trouble formulating a procedural (i.e., non-OOP) script from this example. I'm having trouble accessing the JConfig values. How does one gain access to the JConfig values? This is returning a NULL value for $user:
// We are a valid Joomla entry point.
define("_JEXEC", 1);
// Setup the base path related constant.
define("JPATH_BASE", "/path/to/joomla/install");
// bootstrap the Joomla application
require JPATH_BASE . "/libraries/import.php";
$reg =& JFactory::getConfig();
$user = $reg->get("config.user"); // returns NULL
var_dump($user);
// We are a valid Joomla entry point.
define("_JEXEC", 1);
// Setup the base path related constant.
define("JPATH_BASE", "/path/to/joomla/install");
// bootstrap the Joomla application
require JPATH_BASE . "/libraries/import.php";
$reg =& JFactory::getConfig();
$user = $reg->get("config.user"); // returns NULL
var_dump($user);
make multiplayer flash games: http://flashmog.net
-
- Joomla! Intern
- Posts: 70
- Joined: Mon Jun 21, 2010 12:26 am
Re: Need to use Joomla database credentials/objs in a cron j
It's so hard to get help on this forum. I believe I have managed to boostrap DB access in my script using this code:
I find it puzzling that I need to explicitly instantate the JConfig object.
Code: Select all
// We are a valid Joomla entry point.
defined("_JEXEC") or define("_JEXEC", 1);
// Setup the base path related constant.
defined("JPATH_BASE") or define("JPATH_BASE", "/var/www/erep_v2/html");
// bootstrap the Joomla application
require_once JPATH_BASE . "/libraries/import.php";
// define necessary constants:
require_once JPATH_BASE . '/includes/defines.php';
// Import the configuration.
require_once JPATH_CONFIGURATION . '/configuration.php';
// System configuration.
$joomla_config = new JConfig;
// this will throw a RuntimeException on failure.
$jdbo = JDatabase::getInstance(
array(
"driver" => $joomla_config->dbtype,
"host" => $joomla_config->host,
"user" => $joomla_config->user,
"password" => $joomla_config->password,
"database" => $joomla_config->db,
"prefix" => $joomla_config->dbprefix,
)
);
make multiplayer flash games: http://flashmog.net