English (United Kingdom)
Jms Multi Site, formerly joomla multisite.
Create, share multiple joomla sites in few clicks !
Message
  • EU e-Privacy Directive

    This website uses cookies to manage authentication, navigation, and other functions. By using our website, you agree that we can place these types of cookies on your device.

    View e-Privacy Directive Documents

Welcome, Guest
Please Login or Register.    Lost Password?
Go to bottomPage: 1
TOPIC: site specific cronjob
#4209
site specific cronjob 14 Years, 7 Months ago Karma: 0
Hiya,

I am currently using JMS for some sites. All sites have seperate databases, and I need to trigger a specific custom made plugin every night to do importing into the db, using a cronjob to call a php file. But when I use the cronjob, my file of course is not aware of the site on which to call the plugin (the plugin uses site specific variables). So I was wondering: is it possible to 'manually' call the multisites class in my file which I call with the cronjob, and set the specific site on which to call the plugin?

Maybe the code beneath will explain some more about what I am trying to do:

I call a cronjob like the following (of course with proper path etc.):

Code:


/usr/local/bin/php [path_to_php_file]/cronjob.php 'var1' 'var2' >[path_to_log_file]/log.txt 2>&1



the [path_to_php_file] is a filepath to the php file on the server, so there will be no site specific part in that url (the alias in the apache conf file will not trigger, thus jms will not be aware of the site on which I want to call the plugin).

The php file I call contains the following code, starting the JApplication, triggering the plugin etc:

Code:


<?php
$joomlapath = "[local_server_file_path]/joomlamulti/administrator";
define( '_JEXEC', 1 );
define( 'JPATH_BASE', $joomlapath );
define( 'DS', DIRECTORY_SEPARATOR );

// Load the framework
require_once( JPATH_BASE . DS . 'includes' . DS . 'defines.php' );
require_once( JPATH_BASE . DS . 'includes' . DS . 'framework.php' );
require_once( JPATH_BASE . DS . 'includes' . DS . 'toolbar.php' );

JDEBUG ? $_PROFILER->mark( 'afterLoad' ) : null;

require_once( JPATH_LIBRARIES.DS.'joomla'.DS.'import.php');
jimport( 'joomla.user.user' );
jimport( 'joomla.environment.uri' );
jimport( 'joomla.html.html' );
jimport( 'joomla.utilities.utility' );
jimport( 'joomla.event.event' );
jimport( 'joomla.event.dispatcher' );
jimport( 'joomla.language.language' );
jimport( 'joomla.utilities.string' );

// create the mainframe object
$mainframe = & JFactory::getApplication( 'site' );
// Initialize the framework
$mainframe->initialise();

// load system plugin group
JPluginHelper::importPlugin( 'system' );
// trigger the onAfterInitialise events
JDEBUG ? $_PROFILER->mark('afterInitialise') : null;
$mainframe->triggerEvent('onAfterInitialise');

/************************************************************
It would be nice to be able to set the specific site here, then trigger the event
Create instance of class multisites?
************************************************************/

//get the vars set in the cronjob
if( isset( $argv ) ) {
$var1 = $argv[0];
$var2 = $argv[1];
}

$option = JRequest::getCmd('option');
$mainframe->route();
$mainframe->dispatch($option);
$mainframe->render();

// Perform the Request task
$mainframe->triggerEvent('myImportPlugin');



Any help on this is highly appreciated. Ill be happy to explain it further if necessary.

gr
SaM
SaM
Fresh Boarder
Posts: 3
graphgraph
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
#4215
Re: site specific cronjob 14 Years, 7 Months ago Karma: 54
This will not be easy as JMS is called almost before the first statement present in the file.
In fact it is called in your first "requre_once" and before all Joomla initialisation.
Jms is almost the first statement executed.

If your cron is runing under a "localhost", the only method that could be used is the one documented in the User Manual to force a specific domain using the "_host_" parameter in the URL.
So if you cron is executed from a "localhosst", you could add a parameter in your cron to provide the domain name that you want to execute and use this value to set the _GET['_host_'] with this value.
This should work an inform Jms on which slave site it must initialise Joomla.

So put this '_host_' parameter setting before ALL statement and before all includes and require_once.
edwin2win
Moderator
Posts: 5370
graph
User Offline Click here to see the profile of this user
Last Edit: 2010/05/22 10:06 By edwin2win.
The administrator has disabled public write access.
 
#4220
Re: site specific cronjob 14 Years, 7 Months ago Karma: 0
Hi edwin2win,

thx for the response. After trying with several different options I finally found the solution. Hopefully someone else finds this useful:

With curl, you can call a 'normal' http url, like so:

Code:

/usr/local/bin/curl 'http://www.myDomain.nl/mySubsite/cronjobsfolder/cronjobfile.php?option=com_componentname&controller=myController&task=myTask' >local_file_path_on_server/logProducts.txt


Now that we are able to call the url with the subsite, JMS is aware of the fact that we want to perform the task (trigger the plugin) on that specific subsite.

Works like a charm!

cheers,
SaM
SaM
Fresh Boarder
Posts: 3
graphgraph
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
Go to topPage: 1
get the latest posts directly to your desktop
2Win, Multisite(s) are trademarks of Edwin2Win.
Joomla