upgrade.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * Tidypics upgrade action
  4. */
  5. $plugins_path = elgg_get_plugins_path();
  6. require_once "{$plugins_path}tidypics/version.php";
  7. $local_version = elgg_get_plugin_setting('version', 'tidypics');
  8. if ($version <= $local_version) {
  9. register_error('No upgrade required');
  10. forward(REFERER);
  11. }
  12. set_time_limit(0);
  13. $base_dir = "{$plugins_path}tidypics/upgrades";
  14. // taken from engine/lib/version.php
  15. if ($handle = opendir($base_dir)) {
  16. $upgrades = array();
  17. while ($updatefile = readdir($handle)) {
  18. // Look for upgrades and add to upgrades list
  19. if (!is_dir("$base_dir/$updatefile")) {
  20. if (preg_match('/^([0-9]{10})\.(php)$/', $updatefile, $matches)) {
  21. $plugin_version = (int) $matches[1];
  22. if ($plugin_version > $local_version) {
  23. $upgrades[] = "$base_dir/$updatefile";
  24. }
  25. }
  26. }
  27. }
  28. // Sort and execute
  29. asort($upgrades);
  30. if (sizeof($upgrades) > 0) {
  31. foreach ($upgrades as $upgrade) {
  32. include($upgrade);
  33. }
  34. }
  35. }
  36. elgg_set_plugin_setting('version', $version, 'tidypics');
  37. system_message(elgg_echo('tidypics:upgrade:success'));
  38. forward(REFERER);