PageRenderTime 58ms CodeModel.GetById 32ms RepoModel.GetById 1ms app.codeStats 0ms

/framework/core/zap/ZoneRedo.php

https://github.com/rgigger/zoop
PHP | 101 lines | 32 code | 14 blank | 55 comment | 0 complexity | 2ec56c88601597222a67c70763b9c4ab MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. class ZoneRedo
  3. {
  4. function subMigration($p, $s)
  5. {
  6. $version = $p[3];
  7. SqlBeginTransaction();
  8. $filename = Migration::filenameFromVersion($version);
  9. Migration::undo($filename, $version);
  10. Migration::apply($filename, $version);
  11. SqlCommitTransaction();
  12. }
  13. function subMigrations($p, $s)
  14. {
  15. SqlBeginTransaction();
  16. // make sure the migrations table exists
  17. Migration::initDB();
  18. // have it scan the migrations directory for all available migrations
  19. $versions = Migration::getAllMigrationNames();
  20. // print_r($versions);
  21. $flipped = array_flip($versions);
  22. // query the db for applied migrations in reverse order
  23. $applied = Migration::getAllAppiedMigrationNames();
  24. // print_r($applied);
  25. print_r($versions);
  26. print_r($applied);
  27. // undo all of the migrations
  28. foreach($applied as $key => $migration)
  29. {
  30. Migration::undo($flipped[$migration], $migration);
  31. }
  32. // now, reapply all of them
  33. foreach($versions as $key => $migration)
  34. {
  35. Migration::apply($key, $migration);
  36. }
  37. SqlCommitTransaction();
  38. // apply anything that hasn't been done yet, in the proper order
  39. // $unapplied = array_diff($versions, $applied);
  40. // print_r($unapplied);die();
  41. // foreach($unapplied as $key => $needsApplied)
  42. // {
  43. // Migration::apply($key, $needsApplied);
  44. // }
  45. /*
  46. // make sure the migrations table exists
  47. $schema = SqlGetSchema();
  48. if(!$schema->tableExists('migrations'))
  49. {
  50. SqlAlterSchema("create table migrations (
  51. id serial primary key,
  52. name text not null,
  53. applied int2 not null default 0)");
  54. }
  55. // have it scan the migrations directory for all available migrations
  56. $filenames = ListDir(getcwd() . '/migrations', array('extentions' => array('php')));
  57. $versions = array();
  58. foreach($filenames as $thisFilename)
  59. {
  60. $parts = explode('_', $thisFilename);
  61. $version = $parts[0];
  62. $versions[$thisFilename] = $version;
  63. }
  64. // query the db for applied migrations
  65. $applied = SqlFetchColumn("select name from migrations where applied = 1", array());
  66. // apply anything that hasn't been done yet, in the proper order
  67. $unapplied = array_diff($versions, $applied);
  68. print_r($unapplied);
  69. foreach($unapplied as $key => $needsApplied)
  70. {
  71. // apply the migration
  72. include_once(getcwd() . '/migrations/' . $key);
  73. $className = 'Migration_' . str_replace('.', '_', $needsApplied);
  74. $migration = new $className();
  75. $migration->up();
  76. // mark it as applied
  77. SqlUpsertRow('migrations', array('name' => $needsApplied), array('applied' => 1));
  78. print_r($migration);
  79. }
  80. */
  81. }
  82. }