checkschema.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/usr/bin/env php
  2. <?php
  3. /*
  4. * StatusNet - a distributed open-source microblogging tool
  5. * Copyright (C) 2008-2011 StatusNet, Inc.
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Affero General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. define('INSTALLDIR', dirname(__DIR__));
  21. define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
  22. $shortoptions = 'x::';
  23. $longoptions = array('extensions=');
  24. $helptext = <<<END_OF_CHECKSCHEMA_HELP
  25. php checkschema.php [options]
  26. Gives plugins a chance to update the database schema.
  27. -x --extensions= Comma-separated list of plugins to load before checking
  28. END_OF_CHECKSCHEMA_HELP;
  29. require_once INSTALLDIR.'/scripts/commandline.inc';
  30. function tableDefs()
  31. {
  32. $schema = array();
  33. require INSTALLDIR.'/db/core.php';
  34. return $schema;
  35. }
  36. $schema = Schema::get();
  37. $schemaUpdater = new SchemaUpdater($schema);
  38. foreach (tableDefs() as $table => $def) {
  39. $schemaUpdater->register($table, $def);
  40. }
  41. $schemaUpdater->checkSchema();
  42. if (have_option('x', 'extensions')) {
  43. $ext = trim(get_option_value('x', 'extensions'));
  44. $exts = explode(',', $ext);
  45. foreach ($exts as $plugin) {
  46. try {
  47. addPlugin($plugin);
  48. } catch (Exception $e) {
  49. print $e->getMessage()."\n";
  50. exit(1);
  51. }
  52. }
  53. }
  54. Event::handle('BeforePluginCheckSchema');
  55. Event::handle('CheckSchema');