PageRenderTime 59ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/control/code/trunk/administrator/components/com_control/install/install.php

https://bitbucket.org/eddieajau/the-art-of-joomla-archive
PHP | 395 lines | 262 code | 43 blank | 90 comment | 43 complexity | b641a7d0f1b1657bd048d17927213587 MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: install.php 382 2010-11-03 08:31:13Z eddieajau $
  4. * @package NewLifeInIT
  5. * @subpackage com_control
  6. * @copyright Copyright (C) 2009 New Life in IT Pty Ltd. All rights reserved.
  7. * @license GNU General Public License <http://www.gnu.org/copyleft/gpl.html>
  8. * @link http://www.theartofjoomla.com
  9. */
  10. // no direct access
  11. defined('_JEXEC') or die;
  12. // load the component language file
  13. $language = &JFactory::getLanguage();
  14. $language->load('com_control');
  15. // PHP 5 check
  16. if (version_compare(PHP_VERSION, '5.2.0', '<')) {
  17. $this->parent->abort(JText::_('TAOJ_Use_PHP5'));
  18. return false;
  19. }
  20. //$nPaths = $this->_paths;
  21. $status = new JObject();
  22. $status->modules = array();
  23. $status->plugins = array();
  24. /***********************************************************************************************
  25. * ---------------------------------------------------------------------------------------------
  26. * MODULE INSTALLATION SECTION
  27. * ---------------------------------------------------------------------------------------------
  28. ***********************************************************************************************/
  29. $modules = &$this->manifest->getElementByPath('modules');
  30. if (is_a($modules, 'JSimpleXMLElement') && count($modules->children()))
  31. {
  32. foreach ($modules->children() as $module)
  33. {
  34. $mname = $module->attributes('module');
  35. $mclient = JApplicationHelper::getClientInfo($module->attributes('client'), true);
  36. // Set the installation path
  37. if (!empty ($mname)) {
  38. $this->parent->setPath('extension_root', $mclient->path.DS.'modules'.DS.$mname);
  39. } else {
  40. $this->parent->abort(JText::_('TAOJ_Install_Module').' '.JText::_('TAOJ_Install_Install').': '.JText::_('TAOJ_Install_Module_File_Missing'));
  41. return false;
  42. }
  43. /*
  44. * If the module directory already exists, then we will assume that the
  45. * module is already installed or another module is using that directory.
  46. */
  47. if (file_exists($this->parent->getPath('extension_root'))&&!$this->parent->getOverwrite()) {
  48. $this->parent->abort(JText::_('TAOJ_Install_Module').' '.JText::_('TAOJ_Install_Install').': '.JText::sprintf('TAOJ_Install_Module_Path_Conflict', $this->parent->getPath('extension_root')));
  49. return false;
  50. }
  51. // If the module directory does not exist, lets create it
  52. $created = false;
  53. if (!file_exists($this->parent->getPath('extension_root'))) {
  54. if (!$created = JFolder::create($this->parent->getPath('extension_root'))) {
  55. $this->parent->abort(JText::_('TAOJ_Install_Module').' '.JText::_('TAOJ_Install_Install').': '.JText::sprintf('TAOJ_Install_Module_Path_Create_Failure', $this->parent->getPath('extension_root')));
  56. return false;
  57. }
  58. }
  59. /*
  60. * Since we created the module directory and will want to remove it if
  61. * we have to roll back the installation, lets add it to the
  62. * installation step stack
  63. */
  64. if ($created) {
  65. $this->parent->pushStep(array ('type' => 'folder', 'path' => $this->parent->getPath('extension_root')));
  66. }
  67. // Copy all necessary files
  68. $element = &$module->getElementByPath('files');
  69. if ($this->parent->parseFiles($element, -1) === false) {
  70. // Install failed, roll back changes
  71. $this->parent->abort();
  72. return false;
  73. }
  74. // Copy language files
  75. $element = &$module->getElementByPath('languages');
  76. if ($this->parent->parseLanguages($element, $mclient->id) === false) {
  77. // Install failed, roll back changes
  78. $this->parent->abort();
  79. return false;
  80. }
  81. // Copy media files
  82. $element = &$module->getElementByPath('media');
  83. if ($this->parent->parseMedia($element, $mclient->id) === false) {
  84. // Install failed, roll back changes
  85. $this->parent->abort();
  86. return false;
  87. }
  88. $mtitle = $module->attributes('title');
  89. $mposition = $module->attributes('position');
  90. if ($mtitle && $mposition) {
  91. $row = & JTable::getInstance('module');
  92. $row->title = $mtitle;
  93. $row->ordering = $row->getNextOrder("position='".$mposition."'");
  94. $row->position = $mposition;
  95. $row->showtitle = 0;
  96. $row->iscore = 0;
  97. $row->access = ($mclient->id) == 1 ? 2 : 0;
  98. $row->client_id = $mclient->id;
  99. $row->module = $mname;
  100. $row->published = 0;
  101. $row->params = '';
  102. if (!$row->store()) {
  103. // Install failed, roll back changes
  104. $this->parent->abort(JText::_('TAOJ_Install_Module').' '.JText::_('TAOJ_Install_Install').': '.$db->stderr(true));
  105. return false;
  106. }
  107. }
  108. $status->modules[] = array('name'=>$mname,'client'=>$mclient->name);
  109. }
  110. }
  111. /***********************************************************************************************
  112. * ---------------------------------------------------------------------------------------------
  113. * PLUGIN INSTALLATION SECTION
  114. * ---------------------------------------------------------------------------------------------
  115. ***********************************************************************************************/
  116. $plugins = &$this->manifest->getElementByPath('plugins');
  117. if (is_a($plugins, 'JSimpleXMLElement') && count($plugins->children()))
  118. {
  119. foreach ($plugins->children() as $plugin)
  120. {
  121. $pname = $plugin->attributes('plugin');
  122. $pgroup = $plugin->attributes('group');
  123. // Set the installation path
  124. if (!empty($pname) && !empty($pgroup)) {
  125. $this->parent->setPath('extension_root', JPATH_ROOT.DS.'plugins'.DS.$pgroup);
  126. } else {
  127. $this->parent->abort(JText::_('TAOJ_Install_Plugin').' '.JText::_('TAOJ_Install_Install').': '.JText::_('TAOJ_Install_Plugin_File_Missing'));
  128. return false;
  129. }
  130. /**
  131. * ---------------------------------------------------------------------------------------------
  132. * Filesystem Processing Section
  133. * ---------------------------------------------------------------------------------------------
  134. */
  135. // If the plugin directory does not exist, lets create it
  136. $created = false;
  137. if (!file_exists($this->parent->getPath('extension_root'))) {
  138. if (!$created = JFolder::create($this->parent->getPath('extension_root'))) {
  139. $this->parent->abort(JText::_('TAOJ_Install_Plugin').' '.JText::_('TAOJ_Install_Install').': '.JText::sprintf('TAOJ_Install_Plugin_Path_Create_Failure', $this->parent->getPath('extension_root')));
  140. return false;
  141. }
  142. }
  143. /*
  144. * If we created the plugin directory and will want to remove it if we
  145. * have to roll back the installation, lets add it to the installation
  146. * step stack
  147. */
  148. if ($created) {
  149. $this->parent->pushStep(array ('type' => 'folder', 'path' => $this->parent->getPath('extension_root')));
  150. }
  151. // Copy all necessary files
  152. $element = &$plugin->getElementByPath('files');
  153. if ($this->parent->parseFiles($element, -1) === false) {
  154. // Install failed, roll back changes
  155. $this->parent->abort();
  156. return false;
  157. }
  158. // Copy all necessary files
  159. $element = &$plugin->getElementByPath('languages');
  160. if ($this->parent->parseLanguages($element, 1) === false) {
  161. // Install failed, roll back changes
  162. $this->parent->abort();
  163. return false;
  164. }
  165. // Copy media files
  166. $element = &$plugin->getElementByPath('media');
  167. if ($this->parent->parseMedia($element, 1) === false) {
  168. // Install failed, roll back changes
  169. $this->parent->abort();
  170. return false;
  171. }
  172. /**
  173. * ---------------------------------------------------------------------------------------------
  174. * Database Processing Section
  175. * ---------------------------------------------------------------------------------------------
  176. */
  177. $db = &JFactory::getDBO();
  178. // Check to see if a plugin by the same name is already installed
  179. $query = 'SELECT `id`' .
  180. ' FROM `#__plugins`' .
  181. ' WHERE folder = '.$db->Quote($pgroup) .
  182. ' AND element = '.$db->Quote($pname);
  183. $db->setQuery($query);
  184. if (!$db->Query()) {
  185. // Install failed, roll back changes
  186. $this->parent->abort(JText::_('TAOJ_Install_Plugin').' '.JText::_('TAOJ_Install_Install').': '.$db->stderr(true));
  187. return false;
  188. }
  189. $id = $db->loadResult();
  190. // Was there a plugin already installed with the same name?
  191. if ($id) {
  192. if (!$this->parent->getOverwrite())
  193. {
  194. // Install failed, roll back changes
  195. $this->parent->abort(JText::_('TAOJ_Install_Plugin').' '.JText::_('TAOJ_Install_Install').': '.JText::sprintf('TAOJ_Install_Plugin_Already_Exists', $pname));
  196. return false;
  197. }
  198. } else {
  199. $row =& JTable::getInstance('plugin');
  200. $row->name = JText::_(ucfirst($pgroup)).' - '.JText::_(ucfirst($pname));
  201. $row->ordering = 0;
  202. $row->folder = $pgroup;
  203. $row->iscore = 0;
  204. $row->access = 0;
  205. $row->client_id = 0;
  206. $row->element = $pname;
  207. $row->published = 1;
  208. $row->params = '';
  209. if (!$row->store()) {
  210. // Install failed, roll back changes
  211. $this->parent->abort(JText::_('TAOJ_Install_Plugin').' '.JText::_('TAOJ_Install_Install').': '.$db->stderr(true));
  212. return false;
  213. }
  214. }
  215. $status->plugins[] = array('name'=>$pname,'group'=>$pgroup);
  216. }
  217. }
  218. /***********************************************************************************************
  219. * ---------------------------------------------------------------------------------------------
  220. * SETUP DEFAULTS
  221. * ---------------------------------------------------------------------------------------------
  222. ***********************************************************************************************/
  223. // Insert a new installation record in the version log if no rows are present.
  224. require_once(dirname(dirname(__FILE__)).DS.'version.php');
  225. $version = new ControlVersion();
  226. $db = &JFactory::getDBO();
  227. $tables = $db->getTableList();
  228. // Checking for jxtended version table
  229. if (in_array($db->getPrefix().'jxtended', $tables))
  230. {
  231. // Migrate the old version information
  232. $db->setQuery(
  233. 'INSERT INTO #__taoj (`extension`,`version`, `installed_date`, `log`)'
  234. .' SELECT '.$db->quote('com_control').', `version`, `installed_date`, `log`'
  235. .' FROM `#__jxtended` AS c'
  236. .' WHERE c.extension = '.$db->quote('com_control')
  237. .' ORDER BY `id`'
  238. );
  239. if (!$db->query()) {
  240. // Install failed, roll back changes
  241. $this->parent->abort($db->getErrorMsg());
  242. return false;
  243. }
  244. $db->setQuery(
  245. 'DELETE FROM #__jxtended'
  246. .' WHERE extension = '.$db->quote('com_control')
  247. );
  248. if (!$db->query()) {
  249. // Install failed, roll back changes
  250. $this->parent->abort($db->getErrorMsg());
  251. return false;
  252. }
  253. }
  254. // Checking for the old version table
  255. if (in_array($db->getPrefix().'jxcontrol', $tables))
  256. {
  257. // Migrate the old version information
  258. $db->setQuery(
  259. 'INSERT INTO #__taoj (`extension`,`version`, `installed_date`, `log`)'
  260. .' SELECT '.$db->quote('com_control').', `version`, `installed_date`, `log`'
  261. .' FROM `#__jxcontrol` ORDER BY `installed_date`'
  262. );
  263. if (!$db->Query()) {
  264. // Install failed, roll back changes
  265. $this->parent->abort(JText::_('JXtended Version Migration').': '.$db->stderr(true));
  266. return false;
  267. }
  268. // Drop the old version table
  269. $db->setQuery(
  270. 'DROP TABLE `#__jxcontrol`'
  271. );
  272. if (!$db->Query()) {
  273. // Install failed, roll back changes
  274. $this->parent->abort(JText::_('Version Migration').': '.$db->stderr(true));
  275. return false;
  276. }
  277. }
  278. else
  279. {
  280. $db->setQuery('SELECT COUNT(`version`) FROM `#__taoj` WHERE `extension` = '.$db->quote('com_control'));
  281. if ($db->loadResult() == 0)
  282. {
  283. // Vanilla new install
  284. $db->setQuery(
  285. 'INSERT IGNORE INTO `#__taoj` (`extension`,`version`,`log`)' .
  286. ' VALUES ('.$db->quote('com_control').','.$db->Quote($version->version.'.'.$version->subversion.$version->status).', '.$db->Quote('TAOJ_Install_New_Install').')'
  287. );
  288. $db->query();
  289. }
  290. }
  291. // Correct bug in components table for backend only extenions
  292. $db->setQuery(
  293. 'UPDATE `#__components` SET `link` = '.$db->quote('').' WHERE `option` = '.$db->quote('com_control')
  294. );
  295. if (!$db->query()) {
  296. $this->parent->abort($db->getErrorMsg());
  297. }
  298. /***********************************************************************************************
  299. * ---------------------------------------------------------------------------------------------
  300. * OUTPUT TO SCREEN
  301. * ---------------------------------------------------------------------------------------------
  302. ***********************************************************************************************/
  303. $rows = 0;
  304. ?>
  305. <h2><?php echo JText::_('Control_Install_Heading');?></h2>
  306. <table class="adminlist">
  307. <thead>
  308. <tr>
  309. <th class="title" colspan="2"><?php echo JText::_('TAOJ_Install_Extension'); ?></th>
  310. <th width="30%"><?php echo JText::_('TAOJ_Install_Status'); ?></th>
  311. </tr>
  312. </thead>
  313. <tfoot>
  314. <tr>
  315. <td colspan="3"></td>
  316. </tr>
  317. </tfoot>
  318. <tbody>
  319. <tr class="row0">
  320. <td class="key" colspan="2"><?php echo 'Control '.JText::_('TAOJ_Install_Component'); ?></td>
  321. <td><strong><?php echo JText::_('TAOJ_Install_Installed'); ?></strong></td>
  322. </tr>
  323. <?php if (count($status->modules)) : ?>
  324. <tr>
  325. <th><?php echo JText::_('TAOJ_Install_Module'); ?></th>
  326. <th><?php echo JText::_('TAOJ_Install_Client'); ?></th>
  327. <th></th>
  328. </tr>
  329. <?php foreach ($status->modules as $module) : ?>
  330. <tr class="row<?php echo (++ $rows % 2); ?>">
  331. <td class="key"><?php echo $module['name']; ?></td>
  332. <td class="key"><?php echo ucfirst($module['client']); ?></td>
  333. <td><strong><?php echo JText::_('TAOJ_Install_Installed'); ?></strong></td>
  334. </tr>
  335. <?php endforeach;
  336. endif;
  337. if (count($status->plugins)) : ?>
  338. <tr>
  339. <th><?php echo JText::_('TAOJ_Install_Plugin'); ?></th>
  340. <th><?php echo JText::_('TAOJ_Install_Group'); ?></th>
  341. <th></th>
  342. </tr>
  343. <?php foreach ($status->plugins as $plugin) : ?>
  344. <tr class="row<?php echo (++ $rows % 2); ?>">
  345. <td class="key"><?php echo ucfirst($plugin['name']); ?></td>
  346. <td class="key"><?php echo ucfirst($plugin['group']); ?></td>
  347. <td><strong><?php echo JText::_('TAOJ_Install_Installed'); ?></strong></td>
  348. </tr>
  349. <?php endforeach;
  350. endif; ?>
  351. </tbody>
  352. </table>