示例#1
0
 /**
  * Create a fresh installation of CollectiveAccess based on contents of setup.php.  This is essentially a CLI
  * command wrapper for the installation process, as /install/inc/page2.php is a web wrapper.
  * @param Zend_Console_Getopt $po_opts
  * @param bool $pb_installing
  * @return bool
  */
 public static function install($po_opts = null, $pb_installing = true)
 {
     require_once __CA_BASE_DIR__ . '/install/inc/Installer.php';
     require_once __CA_BASE_DIR__ . '/install/inc/Updater.php';
     if ($pb_installing && !$po_opts->getOption('profile-name')) {
         CLIUtils::addError(_t("Missing required parameter: profile-name"));
         return false;
     }
     if ($pb_installing && !$po_opts->getOption('admin-email')) {
         CLIUtils::addError(_t("Missing required parameter: admin-email"));
         return false;
     }
     $vs_profile_directory = $po_opts->getOption('profile-directory');
     $vs_profile_directory = $vs_profile_directory ? $vs_profile_directory : __CA_BASE_DIR__ . '/install/profiles/xml';
     $t_total = new Timer();
     // If we are installing, then use Installer, otherwise use Updater
     $vo_installer = null;
     if ($pb_installing) {
         $vo_installer = new Installer($vs_profile_directory, $po_opts->getOption('profile-name'), $po_opts->getOption('admin-email'), $po_opts->getOption('overwrite'), $po_opts->getOption('debug'));
     } else {
         $vo_installer = new Updater($vs_profile_directory, $po_opts->getOption('profile-name'), null, false, $po_opts->getOption('debug'));
     }
     $vb_quiet = $po_opts->getOption('quiet');
     // if profile validation against XSD failed, we already have an error here
     if ($vo_installer->numErrors()) {
         CLIUtils::addError(_t("There were errors parsing the profile(s): %1", "\n * " . join("\n * ", $vo_installer->getErrors())));
         return false;
     }
     if ($pb_installing) {
         if (!$vb_quiet) {
             CLIUtils::addMessage(_t("Performing preinstall tasks"));
         }
         $vo_installer->performPreInstallTasks();
         if (!$vb_quiet) {
             CLIUtils::addMessage(_t("Loading schema"));
         }
         $vo_installer->loadSchema();
         if ($vo_installer->numErrors()) {
             CLIUtils::addError(_t("There were errors loading the database schema: %1", "\n * " . join("\n * ", $vo_installer->getErrors())));
             return false;
         }
     }
     if (!$vb_quiet) {
         CLIUtils::addMessage(_t("Processing locales"));
     }
     $vo_installer->processLocales();
     if (!$vb_quiet) {
         CLIUtils::addMessage(_t("Processing lists"));
     }
     $vo_installer->processLists();
     if (!$vb_quiet) {
         CLIUtils::addMessage(_t("Processing relationship types"));
     }
     $vo_installer->processRelationshipTypes();
     if (!$vb_quiet) {
         CLIUtils::addMessage(_t("Processing metadata elements"));
     }
     $vo_installer->processMetadataElements();
     if (!$vb_quiet) {
         CLIUtils::addMessage(_t("Processing metadata dictionary"));
     }
     $vo_installer->processMetadataDictionary();
     if (!$po_opts->getOption('skip-roles')) {
         if (!$vb_quiet) {
             CLIUtils::addMessage(_t("Processing access roles"));
         }
         $vo_installer->processRoles();
     }
     if (!$vb_quiet) {
         CLIUtils::addMessage(_t("Processing user groups"));
     }
     $vo_installer->processGroups();
     if (!$vb_quiet) {
         CLIUtils::addMessage(_t("Processing user logins"));
     }
     $va_login_info = $vo_installer->processLogins();
     if (!$vb_quiet) {
         CLIUtils::addMessage(_t("Processing user interfaces"));
     }
     $vo_installer->processUserInterfaces();
     if (!$vb_quiet) {
         CLIUtils::addMessage(_t("Processing displays"));
     }
     $vo_installer->processDisplays();
     if (!$vb_quiet) {
         CLIUtils::addMessage(_t("Processing search forms"));
     }
     $vo_installer->processSearchForms();
     if (!$vb_quiet) {
         CLIUtils::addMessage(_t("Setting up hierarchies"));
     }
     $vo_installer->processMiscHierarchicalSetup();
     if (!$vb_quiet) {
         CLIUtils::addMessage(_t("Installation complete"));
     }
     $vs_time = _t("Installation took %1 seconds", $t_total->getTime(0));
     if ($vo_installer->numErrors()) {
         CLIUtils::addError(_t("There were errors during installation: %1\n(%2)", "\n * " . join("\n * ", $vo_installer->getErrors()), $vs_time));
         return false;
     }
     if ($pb_installing) {
         CLIUtils::addMessage(_t("Installation was successful!\n\nYou can now login with the following logins: %1\nMake a note of these passwords!", "\n * " . join("\n * ", array_map(function ($username, $password) {
             return _t("username %1 and password %2", $username, $password);
         }, array_keys($va_login_info), array_values($va_login_info)))));
     } else {
         CLIUtils::addMessage(_t("Update of installation profile successful"));
     }
     CLIUtils::addMessage($vs_time);
     return true;
 }