Skip to content
Snippets Groups Projects
Commit f835021d authored by Reinhold Kainhofer's avatar Reinhold Kainhofer
Browse files

V1.10: Fix issues with J3.0; install plugin table on install/update

parent f14ecef6
Branches master
Tags V1.3.2
No related merge requests found
BASE=ordernumber BASE=ordernumber
PLUGINTYPE=vmshopper PLUGINTYPE=vmshopper
VERSION=1.9 VERSION=1.10
PLUGINFILES=$(BASE).php $(BASE).script.php $(BASE).xml index.html PLUGINFILES=$(BASE).php $(BASE).script.php $(BASE).xml index.html
......
...@@ -15,7 +15,6 @@ class plgVmShopperOrdernumber extends vmShopperPlugin { ...@@ -15,7 +15,6 @@ class plgVmShopperOrdernumber extends vmShopperPlugin {
parent::__construct($subject, $config); parent::__construct($subject, $config);
/* Create the database table */ /* Create the database table */
$this->tableFields = array_keys ($this->getTableSQLFields ()); $this->tableFields = array_keys ($this->getTableSQLFields ());
$this->onStoreInstallPluginTable($this->_psType);
} }
public function getVmPluginCreateTableSQL () { public function getVmPluginCreateTableSQL () {
...@@ -140,19 +139,19 @@ class plgVmShopperOrdernumber extends vmShopperPlugin { ...@@ -140,19 +139,19 @@ class plgVmShopperOrdernumber extends vmShopperPlugin {
// Look up the current counter // Look up the current counter
$db = JFactory::getDBO(); $db = JFactory::getDBO();
/* prevent sql injection attacks by escaping the user-entered format! */ /* prevent sql injection attacks by escaping the user-entered format! Empty for global counter... */
$nr_escaped = $db->getEscaped ($nr);
/* For global counting, simply read the empty number_format entries! */ /* For global counting, simply read the empty number_format entries! */
$q = 'SELECT `count` FROM `'.$this->_tablename.'` WHERE `number_type`='.(int)$nrtype.' AND `number_format`="'.($global?"":$nr_escaped).'"'; $nr_escaped = $global?"":$db->getEscaped ($nr);
$q = 'SELECT `count` FROM `'.$this->_tablename.'` WHERE `number_type`='.(int)$nrtype.' AND `number_format`="'.$nr_escaped.'"';
$db->setQuery($q); $db->setQuery($q);
$existing = $db->loadResult(); $existing = $db->loadResult();
$count = $existing?($existing+1):1; $count = $existing?($existing+1):1;
// Insert new counter value into the db // Insert new counter value into the db
if ($existing) { if ($existing) {
$q = 'UPDATE `'.$this->_tablename.'` SET `count`= "'.$count.'" WHERE `number_type`='.(int)$nrtype.' AND `number_format`="'.($global?"":$nr_escaped).'"'; $q = 'UPDATE `'.$this->_tablename.'` SET `count`= "'.$count.'" WHERE `number_type`='.(int)$nrtype.' AND `number_format`="'.$nr_escaped.'"';
} else { } else {
$q = 'INSERT INTO `'.$this->_tablename.'` (`count`, `number_type`, `number_format`) VALUES ('.(int)$count.','.(int)$nrtype.', "'.($global?"":$nr_escaped).'")'; $q = 'INSERT INTO `'.$this->_tablename.'` (`count`, `number_type`, `number_format`) VALUES ('.(int)$count.','.(int)$nrtype.', "'.$nr_escaped.'")';
} }
$db->setQuery( $q ); $db->setQuery( $q );
$db->query(); $db->query();
...@@ -188,7 +187,7 @@ class plgVmShopperOrdernumber extends vmShopperPlugin { ...@@ -188,7 +187,7 @@ class plgVmShopperOrdernumber extends vmShopperPlugin {
$orderstatusForInvoice = VmConfig::get('inv_os',array()); $orderstatusForInvoice = VmConfig::get('inv_os',array());
if(!is_array($orderstatusForInvoice)) $orderstatusForInvoice = array($orderstatusForInvoice); //for backward compatibility 2.0.8e if(!is_array($orderstatusForInvoice)) $orderstatusForInvoice = array($orderstatusForInvoice); //for backward compatibility 2.0.8e
$pdfInvoice = (int)VmConfig::get('pdf_invoice', 0); // backwards compatible $pdfInvoice = (int)VmConfig::get('pdf_invoice', 0); // backwards compatible
$force_create_invoice=JRequest::getInt('create_invoice', 0); $force_create_invoice=JInput::getInt('create_invoice', 0);
if ( in_array($orderDetails['order_status'],$orderstatusForInvoice) or $pdfInvoice==1 or $force_create_invoice==1 ){ if ( in_array($orderDetails['order_status'],$orderstatusForInvoice) or $pdfInvoice==1 or $force_create_invoice==1 ){
$nrtype = 1; /*invoice-nr*/ $nrtype = 1; /*invoice-nr*/
$fmt = $this->params->get ('invoice_number_format', "#"); $fmt = $this->params->get ('invoice_number_format', "#");
...@@ -215,5 +214,11 @@ class plgVmShopperOrdernumber extends vmShopperPlugin { ...@@ -215,5 +214,11 @@ class plgVmShopperOrdernumber extends vmShopperPlugin {
return $data; return $data;
} }
} }
/* In versions before VM 2.6.8, the onStoreInstallPluginTable function was protected, so the installer couldn't call it to create the plugin table...
This function simply is a public wrapper to make this function available to the installer on all VM versions: */
public function plgVmOnStoreInstallPluginTable($psType, $name='') {
return $this->onStoreInstallPluginTable($psType, $name);
}
} }
...@@ -6,6 +6,9 @@ defined('_JEXEC') or die('Restricted access'); ...@@ -6,6 +6,9 @@ defined('_JEXEC') or die('Restricted access');
* @copyright Copyright (C) 2013-2014 Reinhold Kainhofer, office@open-tools.net * @copyright Copyright (C) 2013-2014 Reinhold Kainhofer, office@open-tools.net
* @license GPL v3+, http://www.gnu.org/copyleft/gpl.html * @license GPL v3+, http://www.gnu.org/copyleft/gpl.html
*/ */
defined('DS') or define('DS', DIRECTORY_SEPARATOR);
if (!class_exists( 'VmConfig' ))
require(JPATH_ROOT.DS.'administrator'.DS.'components'.DS.'com_virtuemart'.DS.'helpers'.DS.'config.php');
class plgVmShopperOrdernumberInstallerScript class plgVmShopperOrdernumberInstallerScript
{ {
...@@ -29,12 +32,23 @@ class plgVmShopperOrdernumberInstallerScript ...@@ -29,12 +32,23 @@ class plgVmShopperOrdernumberInstallerScript
/** /**
* Called after any type of action * Called after any type of action
* *
* @param string $route Which action is happening (install|uninstall|discover_install) * @param string $route Which action is happening (install|update|uninstall|discover_install)
* @param JAdapterInstance $adapter The object responsible for running this script * @param JAdapterInstance $adapter The object responsible for running this script
* *
* @return boolean True on success * @return boolean True on success
*/ */
// public function postflight($route, JAdapterInstance $adapter); // public function postflight($route, JAdapterInstance $adapter);
public function postflight ($type, $parent = null) {
if(!class_exists( 'vmPlugin' ))
require JPATH_VM_ADMINISTRATOR.DS.'plugins'.DS.'vmplugin.php';
if(!class_exists( 'plgVmShopperOrdernumber' ))
require JPATH_ROOT.DS.'plugins'.DS.'vmshopper'.DS.'ordernumber'.DS.'ordernumber.php';
$dispatcher = new JDispatcher();
$config = array('name' => 'ordernumber', 'type' => 'vmshopper');
$plugin = new plgVmShopperOrdernumber($dispatcher, $config);
$plugin->plgVmOnStoreInstallPluginTable('shopper');
// $dispatcher->trigger("plgVmOnStoreInstallPluginTable", array('vmshopper'));
}
/** /**
* Called on installation * Called on installation
...@@ -79,7 +93,7 @@ class plgVmShopperOrdernumberInstallerScript ...@@ -79,7 +93,7 @@ class plgVmShopperOrdernumberInstallerScript
{ {
// Remove plugin table // Remove plugin table
$db =& JFactory::getDBO(); $db =& JFactory::getDBO();
$db->setQuery('DROP TABLE `#__virtuemart_shopper_plg_ordernumber`;'); $db->setQuery('DROP TABLE IF EXISTS `#__virtuemart_shopper_plg_ordernumber`;');
$db->query(); $db->query();
} }
} }
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<extension version="1.6" type="plugin" group="vmshopper" method="upgrade"> <extension version="2.5" type="plugin" group="vmshopper" method="upgrade">
<name>VMSHOPPER_ORDERNUMBER</name> <name>VMSHOPPER_ORDERNUMBER</name>
<creationDate>2013-01-09</creationDate> <creationDate>2013-01-09</creationDate>
<author>Reinhold Kainhofer</author> <author>Reinhold Kainhofer</author>
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
<authorUrl>http://www.open-tools.net/</authorUrl> <authorUrl>http://www.open-tools.net/</authorUrl>
<copyright>Copyright (C) 2012-2014 Reinhold Kainhofer. All rights reserved.</copyright> <copyright>Copyright (C) 2012-2014 Reinhold Kainhofer. All rights reserved.</copyright>
<license>http://www.gnu.org/licenses/gpl-3.0.html GNU/GPLv3</license> <license>http://www.gnu.org/licenses/gpl-3.0.html GNU/GPLv3</license>
<version>1.9</version> <version>1.10</version>
<releaseDate>2014-01-13</releaseDate> <releaseDate>2014-08-31</releaseDate>
<releaseType>Minor update</releaseType> <releaseType>Minor update</releaseType>
<downloadUrl>http://www.open-tools.net/virtuemart-2-extensions/vm2-ordernumber-plugin.html</downloadUrl> <downloadUrl>http://www.open-tools.net/virtuemart-2-extensions/vm2-ordernumber-plugin.html</downloadUrl>
...@@ -18,14 +18,14 @@ ...@@ -18,14 +18,14 @@
<filename plugin="ordernumber">ordernumber.php</filename> <filename plugin="ordernumber">ordernumber.php</filename>
<filename>ordernumber.script.php</filename> <filename>ordernumber.script.php</filename>
<filename>index.html</filename> <filename>index.html</filename>
<folder>language</folder> <folder>language</folder>
</files> </files>
<scriptfile>ordernumber.script.php</scriptfile> <scriptfile>ordernumber.script.php</scriptfile>
<languages folder="language"> <languages folder="language">
<language tag="en-GB">en-GB/en-GB.plg_vmshopper_ordernumber.ini</language> <language tag="en-GB">en-GB/en-GB.plg_vmshopper_ordernumber.ini</language>
<language tag="en-GB">en-GB/en-GB.plg_vmshopper_ordernumber.sys.ini</language> <language tag="en-GB">en-GB/en-GB.plg_vmshopper_ordernumber.sys.ini</language>
<language tag="de-DE">de-DE/de-DE.plg_vmshopper_ordernumber.ini</language> <language tag="de-DE">de-DE/de-DE.plg_vmshopper_ordernumber.ini</language>
<language tag="de-DE">de-DE/de-DE.plg_vmshopper_ordernumber.sys.ini</language> <language tag="de-DE">de-DE/de-DE.plg_vmshopper_ordernumber.sys.ini</language>
</languages> </languages>
<!-- Joomla 2.5 & 3.0 config --> <!-- Joomla 2.5 & 3.0 config -->
<config> <config>
......
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment