PageRenderTime 48ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/aamenu/code/trunk/administrator/components/com_aamenu/version.php

https://bitbucket.org/eddieajau/the-art-of-joomla-archive
PHP | 179 lines | 70 code | 23 blank | 86 comment | 8 complexity | 40bb78e760c1ff87c0a682b29d392b57 MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: version.php 269 2010-09-01 00:23:48Z eddieajau $
  4. * @copyright Copyright (C) 2009 New Life in IT Pty Ltd. All rights reserved.
  5. * @license GNU General Public License <http://www.gnu.org/copyleft/gpl.html>
  6. * @link http://www.theartofjoomla.com
  7. */
  8. // no direct access
  9. defined('_JEXEC') or die();
  10. /**
  11. * Version Object
  12. *
  13. * @package Artof.AAMenu
  14. * @subpackage com_aamenu
  15. */
  16. class AAMenuVersion extends JObject
  17. {
  18. /**
  19. * Extension name string.
  20. *
  21. * @var string
  22. */
  23. public $extension = 'com_aamenu';
  24. /**
  25. * Major.Minor version string.
  26. *
  27. * @var string
  28. */
  29. public $version = '1.0';
  30. /**
  31. * Maintenance version string.
  32. *
  33. * @var string
  34. */
  35. public $subversion = '2';
  36. /**
  37. * Version status string.
  38. *
  39. * @var string
  40. */
  41. public $status = '';
  42. /**
  43. * Version release time stamp.
  44. *
  45. * @var string
  46. */
  47. public $date = '2009-06-04 00:00:00';
  48. /**
  49. * Source control revision string.
  50. *
  51. * @var string
  52. */
  53. public $revision = '$Revision: 17 $';
  54. /**
  55. * Container for version information.
  56. *
  57. * @var array
  58. */
  59. protected $_versions = null;
  60. /**
  61. * Container for upgrade information.
  62. *
  63. * @var array
  64. */
  65. protected $_upgrades = null;
  66. /**
  67. * Method to get the build number from the source control revision string.
  68. *
  69. * @return integer The version build number.
  70. */
  71. public function getBuild()
  72. {
  73. return intval(substr($this->revision, 11));
  74. }
  75. /**
  76. * Method to get version history information.
  77. *
  78. * @return array Array of installed versions.
  79. */
  80. public function getVersions()
  81. {
  82. // Only load the versions once.
  83. if (empty($this->_versions))
  84. {
  85. // Initialize variables.
  86. $this->_versions = array();
  87. // Load the version information.
  88. $db = &JFactory::getDBO();
  89. $db->setQuery(
  90. 'SELECT *' .
  91. ' FROM `#__taoj`' .
  92. ' WHERE `extension` = '.$db->quote($this->extension).
  93. ' ORDER BY `id` DESC'
  94. );
  95. $this->_versions = $db->loadObjectList();
  96. // Check for a database error.
  97. if ($db->getErrorNum()) {
  98. $this->setError($db->getErrorMsg());
  99. }
  100. }
  101. return $this->_versions;
  102. }
  103. /**
  104. * Method to get version upgrade information.
  105. *
  106. * @return mixed False on failure, array otherwise.
  107. */
  108. public function getUpgrades()
  109. {
  110. // Only load the upgrades once.
  111. if (empty($this->_upgrades))
  112. {
  113. // Initialize variables.
  114. $this->_upgrades = array();
  115. // Get the version log data.
  116. $versions = $this->getVersions();
  117. // If we have a previously installed version, get the most recent.
  118. if ($last = array_shift($versions))
  119. {
  120. // Get the current and installed version strings.
  121. $currentVersion = $this->version.'.'.$this->subversion.' '.$this->status;
  122. $installedVersion = $last->version;
  123. // Is the current version newer than the last version recorded?
  124. if (version_compare(strtolower($currentVersion), strtolower($installedVersion)) == 1)
  125. {
  126. // Import library dependencies.
  127. jimport('joomla.filesystem.folder');
  128. // Yes, so look for upgrade SQL files.
  129. $files = JFolder::files(JPATH_COMPONENT.DS.'install', '^upgradesql');
  130. // Grab only the upgrade SQL files that are newer than the current version.
  131. foreach ($files as $file)
  132. {
  133. $parts = explode('.', $file);
  134. $fileVersion = str_replace('_', '.', $parts[1]);
  135. if (version_compare($fileVersion, $installedVersion) > 0) {
  136. $this->_upgrades[$fileVersion] = $file;
  137. }
  138. }
  139. }
  140. }
  141. }
  142. return $this->_upgrades;
  143. }
  144. /**
  145. * Method to get version upgrade information.
  146. *
  147. * @return mixed False on failure, array otherwise.
  148. */
  149. public function showUpgrades()
  150. {
  151. if (count($this->getUpgrades())) {
  152. $url = JRoute::_('index.php?option='.$this->extension.'&task=setup.upgrade&'.JUtility::getToken().'=1');
  153. JError::raiseWarning(500, JText::sprintf('TAOJ_Setup_Database_Upgrade_Required', $url));
  154. }
  155. }
  156. }