Encapsulates interface to the actual database.
The DataProviderBase class is located in the file /libraries/pj/DataProvider.php. It implements several concepts:
- It is the interface between Joomla! CMS and the actual DataProvider (MySqlDataProvider only implemented yet). It reads connection settings from JFactory::getConfig(), instantiates the DataProvider, opens database connection and registers several basic Joomla! and PJ classes1;
- intermediates general DataProvider functions like retrieving tables and fields information and executing queries;
- implements basic handling functions for counting, retrieving, listing, updating and deleting of InfoBase objects;
- implements recursive transaction mechanism;
- implements the concept of PJVisitorInfo;
- provides base for development of extension and module specific Joomla! DataProvider classes.
The DataProviderBase class isn't intended for instantiating itself. Instead, the extending class should declare a static instance() function creating a singleton instance. See DataProviderBase API and DataProviderBase Example for further details.
1 The basic registered Joomla! classes are UserInfo, UserProfileInfo, MenuInfo, ModuleInfo, ModuleMenuInfo and ExtensionInfo. Other defined, yet not registered Joomla! classes are CategoryInfo, ContentInfo and LanguageInfo. All predefined Joomla! classes are located in the file /libraries/pj/JoomlaInfo.php. Registered PJ classes are PJVisitorInfo and PJVisitorTcpipInfo, both located in the file /libraries/pj/VisitorInfo.php.
ScriptProvider class extends DataProviderBase. It is located in the file /libraries/pj/ScriptProvider.php.
The ScriptProvider is intended primary for extension installation purposes. Its constructor instantiates the DataProvider and opens the actual database without registering any classes. It implements the only function ExecuteScriptFile ($fileName), doing what is missing in Joomla! JInstaller: installing stored procedures in MySql databases. (This is due the MySql "DELIMITER" clause which is not supported by the Joomla! JDatabaseDriver, but is supported by the DataProviderBase::ExecuteScript function).
A Joomla! extension requiring installation of stored procedures can either extract stored procedures into a separate file and install it in the install($parent) or the postflight($type, $parent) function of its script file, or it can install the whole SQL script file here instead of via manifest file and Joomla! JInstaller.
A scriptfile using the ScriptProvider and the PJVisitorInfo concept could look like this:
defined( '_JEXEC' ) or die;
if(!defined(SCRIPTPROVIDER_FILE))
define('SCRIPTPROVIDER_FILE', JPATH_LIBRARIES . '/pj/ScriptProvider.php');
class com_myextensionInstallerScript
{
function install($parent)
{
if(file_exists(SCRIPTPROVIDER_FILE))
{
require_once SCRIPTPROVIDER_FILE;
$provider = new ScriptProvider();
$script = __DIR__ . '/admin/sql/install.mysql.sp.sql';
$provider->ExecuteScriptFile($script);
$provider->RegisterVisitorTable('com_myextension', 'myfirsttable', 'visitor_id');
$provider->RegisterVisitorTable('com_myextension', 'mysecondtable', 'author_id');
}
}
function uninstall($parent)
{
if(file_exists(SCRIPTPROVIDER_FILE))
{
require_once SCRIPTPROVIDER_FILE;
$provider = new ScriptProvider();
$provider->RegisterVisitorTable('com_myextension');
}
}
function update($parent) {}
function preflight($type, $parent) {}
function postflight($type, $parent) {}
}