upgrade.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /**
  3. * Elgg upgrade library.
  4. * Contains code for handling versioning and upgrades.
  5. *
  6. * @package Elgg.Core
  7. * @subpackage Upgrade
  8. */
  9. /**
  10. * Saves the processed upgrades to a dataset.
  11. *
  12. * @param array $processed_upgrades An array of processed upgrade filenames
  13. * (not the path, just the file)
  14. * @return bool
  15. * @access private
  16. *
  17. * @todo this is still required because of the hack in the 2011010101 upgrade
  18. */
  19. function elgg_set_processed_upgrades(array $processed_upgrades) {
  20. $processed_upgrades = array_unique($processed_upgrades);
  21. return datalist_set('processed_upgrades', serialize($processed_upgrades));
  22. }
  23. /**
  24. * Returns the version of the upgrade filename.
  25. *
  26. * @param string $filename The upgrade filename. No full path.
  27. * @return int|false
  28. * @since 1.8.0
  29. * @access private
  30. * @todo used by elgg_get_upgrade_files
  31. */
  32. function elgg_get_upgrade_file_version($filename) {
  33. preg_match('/^([0-9]{10})([\.a-z0-9-_]+)?\.(php)$/i', $filename, $matches);
  34. if (isset($matches[1])) {
  35. return (int) $matches[1];
  36. }
  37. return false;
  38. }
  39. /**
  40. * Returns a list of upgrade files relative to the $upgrade_path dir.
  41. *
  42. * @param string $upgrade_path The directory that has upgrade scripts
  43. * @return array|false
  44. * @access private
  45. *
  46. * @todo the wire and groups plugins and the installer are using this
  47. */
  48. function elgg_get_upgrade_files($upgrade_path = null) {
  49. if (!$upgrade_path) {
  50. $upgrade_path = elgg_get_root_path() . 'engine/lib/upgrades/';
  51. }
  52. $upgrade_path = sanitise_filepath($upgrade_path);
  53. $handle = opendir($upgrade_path);
  54. if (!$handle) {
  55. return false;
  56. }
  57. $upgrade_files = array();
  58. while ($upgrade_file = readdir($handle)) {
  59. // make sure this is a well formed upgrade.
  60. if (is_dir($upgrade_path . '$upgrade_file')) {
  61. continue;
  62. }
  63. $upgrade_version = elgg_get_upgrade_file_version($upgrade_file);
  64. if (!$upgrade_version) {
  65. continue;
  66. }
  67. $upgrade_files[] = $upgrade_file;
  68. }
  69. sort($upgrade_files);
  70. return $upgrade_files;
  71. }
  72. /**
  73. * Unlocks upgrade.
  74. *
  75. * @access private
  76. *
  77. * @todo the hack in the 2011010101 upgrade requires this
  78. */
  79. function _elgg_upgrade_unlock() {
  80. global $CONFIG;
  81. delete_data("drop table {$CONFIG->dbprefix}upgrade_lock");
  82. elgg_log('Upgrade unlocked.', 'NOTICE');
  83. }