PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/administrator/components/com_virtuemart_allinone/script.vmallinone.php

https://github.com/srgg6701/auction-ruseasons
PHP | 706 lines | 454 code | 125 blank | 127 comment | 93 complexity | 8cac92b3a57bad9f8d488f4e72fa2fc6 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-3.0, LGPL-2.1, BSD-3-Clause, JSON
  1. <?php
  2. defined ('_JEXEC') or die('Restricted access');
  3. /**
  4. * VirtueMart script file
  5. *
  6. * This file is executed during install/upgrade and uninstall
  7. *
  8. * @author Patrick Kohl, Max Milbers
  9. * @package VirtueMart
  10. */
  11. defined ('DS') or define('DS', DIRECTORY_SEPARATOR);
  12. $max_execution_time = ini_get('max_execution_time');
  13. if((int)$max_execution_time<120) {
  14. @ini_set( 'max_execution_time', '120' );
  15. }
  16. $memory_limit = (int) substr(ini_get('memory_limit'),0,-1);
  17. if($memory_limit<128) @ini_set( 'memory_limit', '128M' );
  18. // hack to prevent defining these twice in 1.6 installation
  19. if (!defined ('_VM_SCRIPT_INCLUDED')) {
  20. define('_VM_SCRIPT_INCLUDED', TRUE);
  21. class com_virtuemart_allinoneInstallerScript {
  22. public function preflight () {
  23. //$this->vmInstall();
  24. }
  25. public function install () {
  26. //$this->vmInstall();
  27. }
  28. public function discover_install () {
  29. //$this->vmInstall();
  30. }
  31. public function postflight () {
  32. $this->vmInstall ();
  33. }
  34. public function vmInstall () {
  35. jimport ('joomla.filesystem.file');
  36. jimport ('joomla.installer.installer');
  37. $this->createIndexFolder (JPATH_ROOT . DS . 'plugins' . DS . 'vmcalculation');
  38. $this->createIndexFolder (JPATH_ROOT . DS . 'plugins' . DS . 'vmcustom');
  39. $this->createIndexFolder (JPATH_ROOT . DS . 'plugins' . DS . 'vmpayment');
  40. $this->createIndexFolder (JPATH_ROOT . DS . 'plugins' . DS . 'vmshipment');
  41. $this->path = JInstaller::getInstance ()->getPath ('extension_administrator');
  42. $this->updateShipperToShipment ();
  43. $this->installPlugin ('Standard', 'plugin', 'standard', 'vmpayment');
  44. $this->installPlugin ('Paypal', 'plugin', 'paypal', 'vmpayment');
  45. $this->installPlugin ('PayZen', 'plugin', 'payzen', 'vmpayment');
  46. $this->installPlugin ('SystemPay', 'plugin', 'systempay', 'vmpayment');
  47. //moneybookers
  48. $src = $this->path . DS . 'plugins' . DS . 'vmpayment' . DS . 'moneybookers';
  49. $dst = JPATH_ROOT . DS . 'plugins' . DS . 'vmpayment' . DS . 'moneybookers';
  50. $this->recurse_copy ($src, $dst, 'plugins');
  51. $this->installPlugin ('Moneybookers Credit Cards', 'plugin', 'moneybookers_acc', 'vmpayment');
  52. $this->installPlugin ('Moneybookers Lastschrift', 'plugin', 'moneybookers_did', 'vmpayment');
  53. $this->installPlugin ('Moneybookers iDeal', 'plugin', 'moneybookers_idl', 'vmpayment');
  54. $this->installPlugin ('Moneybookers Giropay', 'plugin', 'moneybookers_gir', 'vmpayment');
  55. $this->installPlugin ('Moneybookers Sofortueberweisung', 'plugin', 'moneybookers_sft', 'vmpayment');
  56. $this->installPlugin ('Moneybookers Przelewy24', 'plugin', 'moneybookers_pwy', 'vmpayment');
  57. $this->installPlugin ('Moneybookers Online Bank Transfer', 'plugin', 'moneybookers_obt', 'vmpayment');
  58. $this->installPlugin ('Moneybookers Skrill Digital Wallet', 'plugin', 'moneybookers_wlt', 'vmpayment');
  59. $this->installPlugin ('Authorize.net', 'plugin', 'authorizenet', 'vmpayment');
  60. $this->installPlugin ('Klarna', 'plugin', 'klarna', 'vmpayment');
  61. $this->installPlugin ('Heidelpay', 'plugin', 'heidelpay', 'vmpayment');
  62. $this->installPlugin ('By weight, ZIP and countries', 'plugin', 'weight_countries', 'vmshipment');
  63. $this->installPlugin ('Customer text input', 'plugin', 'textinput', 'vmcustom');
  64. $this->installPlugin ('Product specification', 'plugin', 'specification', 'vmcustom');
  65. $this->installPlugin ('Stockable variants', 'plugin', 'stockable', 'vmcustom');
  66. $this->installPlugin ('Avalara Tax', 'plugin', 'avalara', 'vmcalculation', 0);
  67. // $table = '#__virtuemart_customs';
  68. // $fieldname = 'field_type';
  69. // $fieldvalue = 'G';
  70. // $this->addToRequired($table,$fieldname,$fieldvalue,"INSERT INTO `#__virtuemart_customs`
  71. // (`custom_parent_id`, `admin_only`, `custom_title`, `custom_tip`, `custom_value`, `custom_field_desc`,
  72. // `field_type`, `is_list`, `is_hidden`, `is_cart_attribute`, `published`) VALUES
  73. // (0, 0, 'COM_VIRTUEMART_STOCKABLE_PRODUCT', 'COM_VIRTUEMART_STOCKABLE_PRODUCT_TIP', NULL,
  74. // 'COM_VIRTUEMART_STOCKABLE_PRODUCT_DESC', 'G', 0, 0, 0, 1 );");
  75. $this->installPlugin ('Virtuemart Product', 'plugin', 'virtuemart', 'search');
  76. $task = JRequest::getCmd ('task');
  77. if ($task != 'updateDatabase') {
  78. // modules auto move
  79. $src = $this->path . DS . "modules";
  80. $dst = JPATH_ROOT . DS . "modules";
  81. $this->recurse_copy ($src, $dst);
  82. echo "Checking VirtueMart2 modules...";
  83. if (!$this->VmModulesAlreadyInstalled ()) {
  84. echo "Installing VirtueMart2 modules<br/ >";
  85. if (version_compare (JVERSION, '1.6.0', 'ge')) {
  86. $defaultParams = '{"text_before":"","product_currency":"","cache":"1","moduleclass_sfx":"","class_sfx":""}';
  87. } else {
  88. $defaultParams = "text_before=\nproduct_currency=\ncache=1\nmoduleclass_sfx=\nclass_sfx=\n";
  89. }
  90. $this->installModule ('VM - Currencies Selector', 'mod_virtuemart_currencies', 4, $defaultParams);
  91. if (version_compare (JVERSION, '1.6.0', 'ge')) {
  92. $defaultParams = '{"product_group":"featured","max_items":"1","products_per_row":"1","display_style":"list","show_price":"1","show_addtocart":"1","headerText":"Best products","footerText":"","filter_category":"0","virtuemart_category_id":"0","cache":"0","moduleclass_sfx":"","class_sfx":""}';
  93. } else {
  94. $defaultParams = "product_group=featured\nmax_items=1\nproducts_per_row=1\ndisplay_style=list\nshow_price=1\nshow_addtocart=1\nheaderText=Best products\nfooterText=\nfilter_category=0\ncategory_id=1\ncache=0\nmoduleclass_sfx=\nclass_sfx=\n";
  95. }
  96. $this->installModule ('VM - Featured products', 'mod_virtuemart_product', 3, $defaultParams);
  97. if (version_compare (JVERSION, '1.6.0', 'ge')) {
  98. $defaultParams = '{"product_group":"topten","max_items":"1","products_per_row":"1","display_style":"list","show_price":"1","show_addtocart":"1","headerText":"","footerText":"","filter_category":"0","virtuemart_category_id":"0","cache":"0","moduleclass_sfx":"","class_sfx":""}';
  99. } else {
  100. $defaultParams = "product_group=topten\nmax_items=1\nproducts_per_row=1\ndisplay_style=list\nshow_price=1\nshow_addtocart=1\nheaderText=\nfooterText=\nfilter_category=0\ncategory_id=1\ncache=0\nmoduleclass_sfx=\nclass_sfx=\n";
  101. }
  102. $this->installModule ('VM - Best Sales', 'mod_virtuemart_product', 1, $defaultParams);
  103. if (version_compare (JVERSION, '1.6.0', 'ge')) {
  104. $defaultParams = '{"width":"20","text":"","button":"","button_pos":"right","imagebutton":"","button_text":""}';
  105. } else {
  106. $defaultParams = "width=20\ntext=\nbutton=\nbutton_pos=right\nimagebutton=\nbutton_text=\nmoduleclass_sfx=\ncache=1\ncache_time=900\n";
  107. }
  108. $this->installModule ('VM - Search in Shop', 'mod_virtuemart_search', 2, $defaultParams);
  109. if (version_compare (JVERSION, '1.6.0', 'ge')) {
  110. $defaultParams = '{"show":"all","display_style":"list","manufacturers_per_row":"1","headerText":"","footerText":""}';
  111. } else {
  112. $defaultParams = "show=all\ndisplay_style=div\nmanufacturers_per_row=1\nheaderText=\nfooterText=\ncache=0\nmoduleclass_sfx=\nclass_sfx=";
  113. }
  114. $this->installModule ('VM - Manufacturer', 'mod_virtuemart_manufacturer', 5, $defaultParams);
  115. if (version_compare (JVERSION, '1.6.0', 'ge')) {
  116. $defaultParams = '{"moduleclass_sfx":"","show_price":"1","show_product_list":"1"}';
  117. } else {
  118. $defaultParams = "moduleclass_sfx=\nshow_price=1\nshow_product_list=1\n";
  119. }
  120. $this->installModule ('VM - Shopping cart', 'mod_virtuemart_cart', 0, $defaultParams);
  121. if (version_compare (JVERSION, '1.6.0', 'ge')) {
  122. $defaultParams = '{"Parent_Category_id":"0","layout":"default","cache":"0","moduleclass_sfx":"","class_sfx":""}';
  123. } else {
  124. $defaultParams = "moduleclass_sfx=\nclass_sfx=\ncategory_name=default\ncache=no\n";
  125. }
  126. $this->installModule ('VM - Category', 'mod_virtuemart_category', 6, $defaultParams);
  127. } else {
  128. echo "VirtueMart2 modules already installed<br/ >";
  129. }
  130. // language auto move
  131. $src = $this->path . DS . "languageFE";
  132. $dst = JPATH_ROOT . DS . "language";
  133. $this->recurse_copy ($src, $dst);
  134. echo " VirtueMart2 language moved to the joomla language FE folder<br/ >";
  135. // language auto move
  136. $src = $this->path . DS . "languageBE";
  137. $dst = JPATH_ADMINISTRATOR . DS . "language";
  138. $this->recurse_copy ($src, $dst);
  139. echo " VirtueMart2 language moved to the joomla language BE folder<br/ >";
  140. // libraries auto move
  141. $src = $this->path . DS . "libraries";
  142. $dst = JPATH_ROOT . DS . "libraries";
  143. $this->recurse_copy ($src, $dst);
  144. echo " VirtueMart2 pdf moved to the joomla libraries folder<br/ >";
  145. //update plugins, make em loggable
  146. /* $loggables = array( 'created_on' => 'DATETIME NOT NULL DEFAULT "0000-00-00 00:00:00"',
  147. 'created_by' => 'INT(11) NOT NULL DEFAULT "0"',
  148. 'modified_on'=> 'DATETIME NOT NULL DEFAULT "0000-00-00 00:00:00"',
  149. 'modified_by'=> 'INT(11) NOT NULL DEFAULT "0"',
  150. 'locked_on' =>'DATETIME NOT NULL DEFAULT "0000-00-00 00:00:00"',
  151. 'locked_by' =>'INT(11) NOT NULL DEFAULT "0"'
  152. );
  153. foreach($loggables as $key => $value){
  154. $this->checkAddFieldToTable('#__virtuemart_payment_paypal',$key,$value);
  155. $this->checkAddFieldToTable('#__virtuemart_payment_standard',$key,$value);
  156. $this->checkAddFieldToTable('#__virtuemart_shipment_weight_countries',$key,$value);
  157. }*/
  158. echo "<H3>Installing Virtuemart Plugins and modules Success.</h3>";
  159. echo "<H3>You may directly uninstall this component. Your plugins will remain</h3>";
  160. echo "<H3>Ignore the message " . JText::_ ('JLIB_INSTALLER_ABORT_COMP_BUILDADMINMENUS_FAILED') . "</h3>";
  161. } else {
  162. echo "<H3>Updated Virtuemart Plugin tables</h3>";
  163. }
  164. return TRUE;
  165. }
  166. /**
  167. * Installs a vm plugin into the database
  168. *
  169. */
  170. private function installPlugin ($name, $type, $element, $group, $published=1) {
  171. $task = JRequest::getCmd ('task');
  172. if ($task != 'updateDatabase') {
  173. $data = array();
  174. if (version_compare (JVERSION, '1.7.0', 'ge')) {
  175. // Joomla! 1.7 code here
  176. $table = JTable::getInstance ('extension');
  177. $data['enabled'] = $published;
  178. $data['access'] = 1;
  179. $tableName = '#__extensions';
  180. $idfield = 'extension_id';
  181. } elseif (version_compare (JVERSION, '1.6.0', 'ge')) {
  182. // Joomla! 1.6 code here
  183. $table = JTable::getInstance ('extension');
  184. $data['enabled'] = $published;
  185. $data['access'] = 1;
  186. $tableName = '#__extensions';
  187. $idfield = 'extension_id';
  188. } else {
  189. // Joomla! 1.5 code here
  190. $table = JTable::getInstance ('plugin');
  191. $data['published'] = $published;
  192. $data['access'] = 0;
  193. $tableName = '#__plugins';
  194. $idfield = 'id';
  195. }
  196. $data['name'] = $name;
  197. $data['type'] = $type;
  198. $data['element'] = $element;
  199. $data['folder'] = $group;
  200. $data['client_id'] = 0;
  201. $src = $this->path . DS . 'plugins' . DS . $group . DS . $element;
  202. $db = JFactory::getDBO ();
  203. $q = 'SELECT COUNT(*) FROM `' . $tableName . '` WHERE `element` = "' . $element . '" and folder = "' . $group . '" ';
  204. $db->setQuery ($q);
  205. $count = $db->loadResult ();
  206. //We write only in the table, when it is not installed already
  207. if ($count == 0) {
  208. // $table->load($count);
  209. if (version_compare (JVERSION, '1.6.0', 'ge')) {
  210. $data['manifest_cache'] = json_encode (JApplicationHelper::parseXMLInstallFile ($src . DS . $element . '.xml'));
  211. }
  212. if (!$table->bind ($data)) {
  213. $app = JFactory::getApplication ();
  214. $app->enqueueMessage ('VMInstaller table->bind throws error for ' . $name . ' ' . $type . ' ' . $element . ' ' . $group);
  215. }
  216. if (!$table->check ($data)) {
  217. $app = JFactory::getApplication ();
  218. $app->enqueueMessage ('VMInstaller table->check throws error for ' . $name . ' ' . $type . ' ' . $element . ' ' . $group);
  219. }
  220. if (!$table->store ($data)) {
  221. $app = JFactory::getApplication ();
  222. $app->enqueueMessage ('VMInstaller table->store throws error for ' . $name . ' ' . $type . ' ' . $element . ' ' . $group);
  223. }
  224. $errors = $table->getErrors ();
  225. foreach ($errors as $error) {
  226. $app = JFactory::getApplication ();
  227. $app->enqueueMessage (get_class ($this) . '::store ' . $error);
  228. }
  229. // remove duplicated
  230. } elseif ($count == 2) {
  231. $q = 'SELECT ' . $idfield . ' FROM `' . $tableName . '` WHERE `element` = "' . $element . '" ORDER BY `' . $idfield . '` DESC LIMIT 0,1';
  232. $db->setQuery ($q);
  233. $duplicatedPlugin = $db->loadResult ();
  234. $q = 'DELETE FROM `' . $tableName . '` WHERE ' . $idfield . ' = ' . $duplicatedPlugin;
  235. $db->setQuery ($q);
  236. $db->query ();
  237. }
  238. }
  239. if (version_compare (JVERSION, '1.7.0', 'ge')) {
  240. // Joomla! 1.7 code here
  241. $dst = JPATH_ROOT . DS . 'plugins' . DS . $group . DS . $element;
  242. } elseif (version_compare (JVERSION, '1.6.0', 'ge')) {
  243. // Joomla! 1.6 code here
  244. $dst = JPATH_ROOT . DS . 'plugins' . DS . $group . DS . $element;
  245. } else {
  246. // Joomla! 1.5 code here
  247. $dst = JPATH_ROOT . DS . 'plugins' . DS . $group;
  248. }
  249. if ($task != 'updateDatabase') {
  250. $this->recurse_copy ($src, $dst);
  251. }
  252. if ($group != 'search') {
  253. $this->updatePluginTable ($name, $type, $element, $group, $dst);
  254. } else {
  255. if (version_compare (JVERSION, '1.6.0', 'ge')) {
  256. $this->updatePluginTable ($name, $type, $element, $group, $dst);
  257. }
  258. }
  259. }
  260. public function updatePluginTable ($name, $type, $element, $group, $dst) {
  261. $app = JFactory::getApplication ();
  262. //Update Tables
  263. if (!class_exists ('VmConfig')) {
  264. require(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_virtuemart' . DS . 'helpers' . DS . 'config.php');
  265. }
  266. if (class_exists ('VmConfig')) {
  267. $pluginfilename = $dst . DS . $element . '.php';
  268. require ($pluginfilename);
  269. //plgVmpaymentPaypal
  270. $pluginClassname = 'plg' . ucfirst ($group) . ucfirst ($element);
  271. //Let's get the global dispatcher
  272. $dispatcher = JDispatcher::getInstance ();
  273. $config = array('type'=> $group, 'name'=> $group, 'params'=> '');
  274. $plugin = new $pluginClassname($dispatcher, $config);
  275. ;
  276. // $updateString = $plugin->getVmPluginCreateTableSQL();
  277. //if(function_exists($plugin->getTableSQLFields)){
  278. $_psType = substr ($group, 2);
  279. $tablename = '#__virtuemart_' . $_psType . '_plg_' . $element;
  280. $db = JFactory::getDBO ();
  281. $prefix=$db->getPrefix();
  282. $query = 'SHOW TABLES LIKE "' . str_replace ('#__', $prefix, $tablename) . '"';
  283. $db->setQuery ($query);
  284. $result = $db->loadResult ();
  285. //$app -> enqueueMessage( get_class( $this ).':: '.$query.' '.$result);
  286. if ($result) {
  287. $SQLfields = $plugin->getTableSQLFields ();
  288. $loggablefields = $plugin->getTableSQLLoggablefields ();
  289. $tablesFields = array_merge ($SQLfields, $loggablefields);
  290. $update[$tablename] = array($tablesFields, array(), array());
  291. vmdebug('install plugin',$update );
  292. $app->enqueueMessage (get_class ($this) . ':: VirtueMart2 update ' . $tablename);
  293. if (!class_exists ('GenericTableUpdater')) {
  294. require(JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'tableupdater.php');
  295. }
  296. $updater = new GenericTableUpdater();
  297. $updater->updateMyVmTables ($update);
  298. }
  299. //}
  300. // } else {
  301. // $app = JFactory::getApplication();
  302. // $app -> enqueueMessage( get_class( $plugin ).':: VirtueMart2 function getTableSQLFields not found');
  303. // }
  304. } else {
  305. $app = JFactory::getApplication ();
  306. $app->enqueueMessage (get_class ($this) . ':: VirtueMart2 must be installed, or the tables cant be updated ' . $error);
  307. }
  308. }
  309. public function installModule ($title, $module, $ordering, $params) {
  310. $params = '';
  311. $table = JTable::getInstance ('module');
  312. $db = $table->getDBO ();
  313. $q = 'SELECT id FROM `#__modules` WHERE `module` = "' . $module . '" ';
  314. $db->setQuery ($q);
  315. $id = $db->loadResult ();
  316. $src = JPATH_ROOT . DS . 'modules' . DS . $module;
  317. if (!empty($id)) {
  318. return;
  319. }
  320. $table->load ();
  321. if (version_compare (JVERSION, '1.7.0', 'ge')) {
  322. // Joomla! 1.7 code here
  323. $position = 'position-4';
  324. $access = 1;
  325. } else {
  326. if (version_compare (JVERSION, '1.6.0', 'ge')) {
  327. // Joomla! 1.6 code here
  328. $access = 1;
  329. } else {
  330. // Joomla! 1.5 code here
  331. $position = 'left';
  332. $access = 0;
  333. }
  334. }
  335. if (empty($table->title)) {
  336. $table->title = $title;
  337. }
  338. if (empty($table->ordering)) {
  339. $table->ordering = $ordering;
  340. }
  341. if (empty($table->published)) {
  342. $table->published = 1;
  343. }
  344. if (empty($table->module)) {
  345. $table->module = $module;
  346. }
  347. if (empty($table->params)) {
  348. $table->params = $params;
  349. }
  350. if (empty($table->access)) {
  351. $table->access = $access;
  352. }
  353. if (empty($table->position)) {
  354. $table->position = $position;
  355. }
  356. if (empty($table->client_id)) {
  357. $table->client_id = $client_id = 0;
  358. }
  359. // $data['manifest_cache'] ='';
  360. // if(!empty($id)){
  361. // unset($data['manifest_cache']);
  362. // $table->load($id);
  363. // if(empty($table->manifest_cache)){
  364. // if(version_compare(JVERSION,'1.6.0','ge')) {
  365. // $data['manifest_cache'] = json_encode(JApplicationHelper::parseXMLInstallFile($src.DS.$module.'.xml'));
  366. // }
  367. // }
  368. // }
  369. // if(empty($count)){
  370. // if(!$table->bind($data)){
  371. // $app = JFactory::getApplication();
  372. // $app -> enqueueMessage('VMInstaller table->bind throws error for '.$title.' '.$module.' '.$params);
  373. // }
  374. if (!$table->check ()) {
  375. $app = JFactory::getApplication ();
  376. $app->enqueueMessage ('VMInstaller table->check throws error for ' . $title . ' ' . $module . ' ' . $params);
  377. }
  378. if (!$table->store ()) {
  379. $app = JFactory::getApplication ();
  380. $app->enqueueMessage ('VMInstaller table->store throws error for for ' . $title . ' ' . $module . ' ' . $params);
  381. }
  382. $errors = $table->getErrors ();
  383. foreach ($errors as $error) {
  384. $app = JFactory::getApplication ();
  385. $app->enqueueMessage (get_class ($this) . '::store ' . $error);
  386. }
  387. // }
  388. $lastUsedId = $table->id;
  389. $q = 'SELECT moduleid FROM `#__modules_menu` WHERE `moduleid` = "' . $lastUsedId . '" ';
  390. $db->setQuery ($q);
  391. $moduleid = $db->loadResult ();
  392. $action = '';
  393. if (empty($moduleid)) {
  394. $q = 'INSERT INTO `#__modules_menu` (`moduleid`, `menuid`) VALUES( "' . $lastUsedId . '" , "0");';
  395. } else {
  396. //$q = 'UPDATE `#__modules_menu` SET `menuid`= "0" WHERE `moduleid`= "'.$moduleid.'" ';
  397. }
  398. $db->setQuery ($q);
  399. $db->query ();
  400. if (version_compare (JVERSION, '1.6.0', 'ge')) {
  401. $q = 'SELECT extension_id FROM `#__extensions` WHERE `element` = "' . $module . '" ';
  402. $db->setQuery ($q);
  403. $ext_id = $db->loadResult ();
  404. // $manifestCache = str_replace('"', '\'', $data["manifest_cache"]);
  405. $action = '';
  406. if (empty($ext_id)) {
  407. if (version_compare (JVERSION, '1.6.0', 'ge')) {
  408. $manifest_cache = json_encode (JApplicationHelper::parseXMLInstallFile ($src . DS . $module . '.xml'));
  409. }
  410. $q = 'INSERT INTO `#__extensions` (`name`, `type`, `element`, `folder`, `client_id`, `enabled`, `access`, `protected`, `manifest_cache`, `params`, `ordering`) VALUES
  411. ( "' . $module . '" , "module", "' . $module . '", "", "0", "1","' . $access . '", "0", "' . $db->getEscaped ($manifest_cache) . '", "' . $params . '","' . $ordering . '");';
  412. } else {
  413. /* $q = 'UPDATE `#__extensions` SET `name`= "'.$module.'",
  414. `type`= "module",
  415. `element`= "'.$module.'",
  416. `folder`= "",
  417. `client_id`= "'.$client_id.'",
  418. `enabled`= "1",
  419. `access`= "'.$access.'",
  420. `protected`= "0",
  421. `ordering`= "'.$ordering.'"
  422. WHERE `extension_id`= "'.$ext_id.'" ';*/
  423. }
  424. $db->setQuery ($q);
  425. if (!$db->query ()) {
  426. $app = JFactory::getApplication ();
  427. $app->enqueueMessage (get_class ($this) . ':: ' . $db->getErrorMsg ());
  428. }
  429. }
  430. }
  431. public function VmModulesAlreadyInstalled () {
  432. // when the modules are already installed publish=-2
  433. $table = JTable::getInstance ('module');
  434. $db = $table->getDBO ();
  435. $q = 'SELECT count(*) FROM `#__modules` WHERE `module` LIKE "mod_virtuemart_%"';
  436. $db->setQuery ($q);
  437. $count = $db->loadResult ();
  438. return $count;
  439. }
  440. /**
  441. * @author Max Milbers
  442. * @param string $tablename
  443. * @param string $fields
  444. * @param string $command
  445. */
  446. private function alterTable ($tablename, $fields, $command = 'CHANGE') {
  447. if (empty($this->db)) {
  448. $this->db = JFactory::getDBO ();
  449. }
  450. $query = 'SHOW COLUMNS FROM `' . $tablename . '` ';
  451. $this->db->setQuery ($query);
  452. $columns = $this->db->loadResultArray (0);
  453. foreach ($fields as $fieldname => $alterCommand) {
  454. if (in_array ($fieldname, $columns)) {
  455. $query = 'ALTER TABLE `' . $tablename . '` ' . $command . ' COLUMN `' . $fieldname . '` ' . $alterCommand;
  456. $this->db->setQuery ($query);
  457. $this->db->query ();
  458. }
  459. }
  460. }
  461. /**
  462. *
  463. * @author Max Milbers
  464. * @param string $table
  465. * @param string $field
  466. * @param string $fieldType
  467. * @return boolean This gives true back, WHEN it altered the table, you may use this information to decide for extra post actions
  468. */
  469. private function checkAddFieldToTable ($table, $field, $fieldType) {
  470. $query = 'SHOW COLUMNS FROM `' . $table . '` ';
  471. $this->db->setQuery ($query);
  472. $columns = $this->db->loadResultArray (0);
  473. if (!in_array ($field, $columns)) {
  474. $query = 'ALTER TABLE `' . $table . '` ADD ' . $field . ' ' . $fieldType;
  475. $this->db->setQuery ($query);
  476. if (!$this->db->query ()) {
  477. $app = JFactory::getApplication ();
  478. $app->enqueueMessage ('Install checkAddFieldToTable ' . $this->db->getErrorMsg ());
  479. return FALSE;
  480. } else {
  481. return TRUE;
  482. }
  483. }
  484. return FALSE;
  485. }
  486. private function updateShipperToShipment () {
  487. if (empty($this->db)) {
  488. $this->db = JFactory::getDBO ();
  489. }
  490. if (version_compare (JVERSION, '1.6.0', 'ge')) {
  491. // Joomla! 1.6 code here
  492. $table = JTable::getInstance ('extension');
  493. $tableName = '#__extensions';
  494. $idfield = 'extension_id';
  495. } else {
  496. // Joomla! 1.5 code here
  497. $table = JTable::getInstance ('plugin');
  498. $tableName = '#__plugins';
  499. $idfield = 'id';
  500. }
  501. $q = 'SELECT ' . $idfield . ' FROM ' . $tableName . ' WHERE `folder` = "vmshipper" ';
  502. $this->db->setQuery ($q);
  503. $result = $this->db->loadResult ();
  504. if ($result) {
  505. $q = 'UPDATE `' . $tableName . '` SET `folder`="vmshipment" WHERE `extension_id`= ' . $result;
  506. $this->db->setQuery ($q);
  507. $this->db->query ();
  508. }
  509. }
  510. /**
  511. * copy all $src to $dst folder and remove it
  512. *
  513. * @author Max Milbers
  514. * @param String $src path
  515. * @param String $dst path
  516. * @param String $type modules, plugins, languageBE, languageFE
  517. */
  518. private function recurse_copy ($src, $dst) {
  519. $dir = opendir ($src);
  520. $this->createIndexFolder ($dst);
  521. if (is_resource ($dir)) {
  522. while (FALSE !== ($file = readdir ($dir))) {
  523. if (($file != '.') && ($file != '..')) {
  524. if (is_dir ($src . DS . $file)) {
  525. $this->recurse_copy ($src . DS . $file, $dst . DS . $file);
  526. } else {
  527. if (JFile::exists ($dst . DS . $file)) {
  528. if (!JFile::delete ($dst . DS . $file)) {
  529. $app = JFactory::getApplication ();
  530. $app->enqueueMessage ('Couldnt delete ' . $dst . DS . $file);
  531. }
  532. }
  533. if (!JFile::move ($src . DS . $file, $dst . DS . $file)) {
  534. $app = JFactory::getApplication ();
  535. $app->enqueueMessage ('Couldnt move ' . $src . DS . $file . ' to ' . $dst . DS . $file);
  536. }
  537. }
  538. }
  539. }
  540. closedir ($dir);
  541. if (is_dir ($src)) {
  542. JFolder::delete ($src);
  543. }
  544. } else {
  545. $app = JFactory::getApplication ();
  546. $app->enqueueMessage ('Couldnt read dir ' . $dir . ' source ' . $src);
  547. }
  548. }
  549. public function uninstall () {
  550. return TRUE;
  551. }
  552. /**
  553. * creates a folder with empty html file
  554. *
  555. * @author Max Milbers
  556. *
  557. */
  558. public function createIndexFolder ($path) {
  559. if (JFolder::create ($path)) {
  560. if (!JFile::exists ($path . DS . 'index.html')) {
  561. JFile::copy (JPATH_ROOT . DS . 'components' . DS . 'index.html', $path . DS . 'index.html');
  562. }
  563. return TRUE;
  564. }
  565. return FALSE;
  566. }
  567. }
  568. // PLZ look in #vminstall.php# to add your plugin and module
  569. function com_install () {
  570. if (!version_compare (JVERSION, '1.6.0', 'ge')) {
  571. $vmInstall = new com_virtuemart_allinoneInstallerScript();
  572. $vmInstall->vmInstall ();
  573. }
  574. return TRUE;
  575. }
  576. function com_uninstall () {
  577. return TRUE;
  578. }
  579. } //if defined
  580. // pure php no tag