Advertisement
Guest User

Untitled

a guest
Jan 16th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. <?php
  2. /**
  3. * Script to fix start/end/min/max for all routes
  4. *
  5. * You have to set your database connection within this file to enable the script.
  6. * Remember to delete your credentials afterwards to protect this script.
  7. *
  8. * Hint: This script is currently only a dirty hack. Don't rely on this in future versions.
  9. * @since 2.1
  10. */
  11. $hostname = 'localhost';
  12. $database = 'runalyze';
  13. $username = 'root';
  14. $password = '';
  15. $port = '3306';
  16.  
  17. define('PREFIX', 'runalyze_');
  18. define('CLI', false); // Set to true if running from command line
  19.  
  20. // Uncomment these lines to unset time/memory limits
  21. //@ini_set('memory_limit', '-1');
  22. //if (!ini_get('safe_mode')) { @set_time_limit(0); }
  23.  
  24.  
  25. /*******************************************************************************
  26. * SCRIPT STARTS - YOU DON'T NEED TO CHANGE ANYTHING BELOW
  27. ******************************************************************************/
  28.  
  29. $starttime = microtime(true);
  30.  
  31. /**
  32. * Protect script
  33. */
  34. define('EOL', CLI ? PHP_EOL : '<br>'.PHP_EOL);
  35. define('GLOBAL_CLEANUP', true);
  36.  
  37. if (empty($database) && empty($hostname)) {
  38. echo 'Database connection has to be set within the file.'.EOL;
  39. exit;
  40. } else {
  41. date_default_timezone_set('Europe/Berlin');
  42.  
  43. define('FRONTEND_PATH', __DIR__.'/../inc/');
  44.  
  45. require_once FRONTEND_PATH.'/system/class.Autoloader.php';
  46. new Autoloader();
  47.  
  48. try {
  49. DB::connect($hostname, $port, $username, $password, $database);
  50. $PDO = DB::getInstance();
  51. $PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  52. } catch (Exception $E) {
  53. echo 'Database connection failed: '.$E->getMessage().EOL;
  54. exit;
  55. }
  56.  
  57. require_once FRONTEND_PATH.'/system/class.Cache.php';
  58. new Cache();
  59.  
  60. require_once FRONTEND_PATH.'/system/define.consts.php';
  61.  
  62. if (!function_exists('__')) {
  63. function __($t) {
  64. return $t;
  65. }
  66. }
  67. }
  68.  
  69. /**
  70. * Set class to handle account id
  71. * @see SessionAccountHandler
  72. */
  73. class GlobalCleanupAccount {
  74. public static $ID;
  75. }
  76.  
  77. /**
  78. * Prepare fix
  79. */
  80. echo 'Start to fix routes ';
  81.  
  82. /**
  83. * Run single cleanups
  84. */
  85. $Routes = $PDO->query('
  86. SELECT
  87. `id`,
  88. `accountid`,
  89. `geohashes`
  90. FROM `'.PREFIX.'route`
  91. WHERE `startpoint` = "7zzzzzzzzz"'
  92. );
  93. $Updater = new Runalyze\Model\Route\Updater($PDO);
  94.  
  95. while ($Route = $Routes->fetch()) {
  96. $Updater->setAccountID($Route['accountid']);
  97. GlobalCleanupAccount::$ID = $Route['accountid'];
  98. $PDO->setAccountID($Route['accountid']);
  99.  
  100. $Updater->update(new Runalyze\Model\Route\Entity($Route), array(
  101. 'startpoint',
  102. 'endpoint',
  103. 'min',
  104. 'max'
  105. ));
  106.  
  107. echo '.'.(CLI ? '' : ' ');
  108. }
  109.  
  110. /**
  111. * Finish
  112. */
  113. echo 'done;'.EOL;
  114. echo EOL;
  115. echo 'Time: '.(microtime(true) - $starttime).'s'.EOL;
  116. echo 'Memory peak: '.memory_get_peak_usage().'B'.EOL;
  117. echo EOL;
  118.  
  119. echo 'You are done. All routes are cleaned.'.EOL;
  120.  
  121. echo EOL;
  122. echo 'Remember to unset your credentials within this file.'.EOL;
  123. echo '(Or simply delete this file if you are not working on our git repository)'.EOL;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement