RoundCube Webmail
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.9 KiB

  1. #!/usr/bin/env php
  2. <?php
  3. /*
  4. +-----------------------------------------------------------------------+
  5. | This file is part of the Roundcube Webmail client |
  6. | |
  7. | Copyright (C) The Roundcube Dev Team |
  8. | Copyright (C) Kolab Systems AG |
  9. | |
  10. | Licensed under the GNU General Public License version 3 or |
  11. | any later version with exceptions for skins & plugins. |
  12. | See the README file for a full license statement. |
  13. | |
  14. | PURPOSE: |
  15. | Create database schema |
  16. +-----------------------------------------------------------------------+
  17. | Author: Aleksander Machniak <alec@alec.pl> |
  18. +-----------------------------------------------------------------------+
  19. */
  20. define('INSTALL_PATH', realpath(__DIR__ . '/..') . '/' );
  21. require_once INSTALL_PATH . 'program/include/clisetup.php';
  22. // get arguments
  23. $opts = rcube_utils::get_opt([
  24. 'd' => 'dir',
  25. 'u' => 'update'
  26. ]);
  27. if (empty($opts['dir'])) {
  28. rcube::raise_error("Database schema directory not specified (--dir).", false, true);
  29. }
  30. // Check if directory exists
  31. if (!file_exists($opts['dir'])) {
  32. rcube::raise_error("Specified database schema directory doesn't exist.", false, true);
  33. }
  34. $db = rcmail_utils::db();
  35. if (!empty($opts['update']) && in_array($db->table_name('system'), (array)$db->list_tables())) {
  36. echo "Checking for database schema updates..." . PHP_EOL;
  37. rcmail_utils::db_update($opts['dir'], 'roundcube', null, ['errors' => true]);
  38. } else {
  39. rcmail_utils::db_init($opts['dir']);
  40. }