/**
  * Start behat process for generating site contents.
  */
 protected function generate()
 {
     $generatorfeaturepath = util::get_tool_dir();
     // Execute each feature file 1 by one to show the proper progress...
     $generatorconfig = util::get_feature_config();
     if (empty($generatorconfig)) {
         util::performance_exception("Check generator config file.");
     }
     // Create test feature file depending on what is given.
     foreach ($generatorconfig as $featuretoadd => $config) {
         $finalfeaturepath = $generatorfeaturepath . DIRECTORY_SEPARATOR . $featuretoadd . '.feature';
         if (file_exists($finalfeaturepath)) {
             self::log($featuretoadd);
             $status = $this->execute_behat_generator($featuretoadd, $finalfeaturepath);
             // Don't proceed...
             if ($status) {
                 echo "Error: Failed generating data for " . $featuretoadd . PHP_EOL . PHP_EOL;
                 exit(1);
             }
             self::end_log();
         }
     }
 }
 /**
  * Checks whether the test database and dataroot is ready
  * Stops execution if something went wrong
  * @throws moodle_exception
  * @return string error code.
  */
 protected static function test_environment_problem()
 {
     global $DB;
     if (!defined('PERFORMANCE_SITE_GENERATOR')) {
         util::performance_exception('This method can be only used by performance site generator.');
     }
     $tables = $DB->get_tables(false);
     if (empty($tables)) {
         return self::SITE_ERROR_INSTALL;
     }
     if (!self::is_site_data_updated()) {
         return self::SITE_ERROR_REINSTALL;
     }
     // No error.
     return self::SITE_ERROR_INSTALLED;
 }
 /**
  * Restore state of current site. Dataroot and database.
  *
  * @param string $statename
  * @return int 0 on success else error code.
  */
 public static function restore_site_state($statename = "default")
 {
     // Clean up the dataroot folder.
     util::drop_dir(self::get_dataroot() . '/');
     // Restore database and dataroot state, before proceeding.
     echo "Restoring database state" . PHP_EOL;
     if (!self::restore_database_state($statename)) {
         util::performance_exception("Error restoring state db: " . $statename);
     }
     echo "Restoring dataroot state" . PHP_EOL;
     if (!self::restore_dataroot($statename)) {
         util::performance_exception("Error restoring state data: " . $statename);
     }
     echo "Site restored to {$statename} state" . PHP_EOL;
     return 0;
 }