Example #1
0
 /**
  * methods raises an exception by throwing a ExceptionController exception.
  *
  * @param string $text
  * @param bool $stop_execution
  * @param callable|null $catched_exception
  * @return void
  * @throws \Thallium\Controllers\ExceptionController
  */
 public static function raiseError($text, $stop_execution = false, $catched_exception = null)
 {
     if (!isset($text) || empty($text) || !is_string($text)) {
         $text = "Unspecified error.";
     }
     if (!isset($stop_execution) || !is_bool($stop_execution)) {
         $stop_execution = false;
     }
     if (isset($catched_exception) && !is_null($catched_exception) && !is_object($catched_exception)) {
         $catched_exception = null;
     }
     // If in test-mode, just throw the exception and return.
     // It is then phpunits job to pick up the exception.
     if (MainController::inTestMode()) {
         throw new ExceptionController($text, $catched_exception);
         return;
     }
     try {
         throw new ExceptionController($text, $catched_exception);
     } catch (\Thallium\Controllers\ExceptionController $e) {
         if ($e->printsJson()) {
             print $e;
             exit(1);
         }
         // if Previous exceptions have been captured, first display that ones.
         $prev = $e;
         while ($prev = $prev->getPrevious()) {
             print $prev;
         }
         // now finally print the actually captured exception.
         print $e;
     }
     if ($stop_execution === true) {
         trigger_error("Execution stopped.", E_USER_ERROR);
     }
     return;
 }
Example #2
0
 /**
  * this is the public accessible method that triggers the installation process.
  *
  * @param none
  * @return bool
  * @throws \Thallium\Controllers\ExceptionController if an error occurs.
  */
 public function setup()
 {
     global $db, $config;
     if ($db->checkTableExists("TABLEPREFIXmeta")) {
         if (($this->schema_version_before = $db->getApplicationDatabaseSchemaVersion()) === false) {
             static::raiseError(get_class($db) . '::getApplicationDatabaseSchemaVersion() returned false!');
             return false;
         }
         if (($this->framework_schema_version_before = $db->getFrameworkDatabaseSchemaVersion()) === false) {
             static::raiseError(get_class($db) . '::getFrameworkDatabaseSchemaVersion() returned false!');
             return false;
         }
     }
     if (!isset($this->schema_version_before)) {
         $this->schema_version_before = 0;
     }
     if (!isset($this->framework_schema_version_before)) {
         $this->framework_schema_version_before = 0;
     }
     if ($this->schema_version_before < $db->getApplicationSoftwareSchemaVersion() || $this->framework_schema_version_before < $db->getFrameworkSoftwareSchemaVersion()) {
         if (!$this->createDatabaseTables()) {
             static::raiseError(__CLASS__ . '::createDatabaseTables() returned false!');
             return false;
         }
     }
     if ($db->getApplicationDatabaseSchemaVersion() < $db->getApplicationSoftwareSchemaVersion() || $db->getFrameworkDatabaseSchemaVersion() < $db->getFrameworkSoftwareSchemaVersion()) {
         if (!$this->upgradeDatabaseSchema()) {
             static::raiseError(__CLASS__ . '::upgradeDatabaseSchema() returned false!');
             return false;
         }
     }
     if (MainController::inTestMode()) {
         return true;
     }
     if (!empty($this->schema_version_before)) {
         printf('Application database schema version before upgrade: %s<br />', $this->schema_version_before);
     }
     printf('Application software supported schema version: %s<br />', $db->getApplicationSoftwareSchemaVersion());
     printf('Application database schema version after upgrade: %s<br />', $db->getApplicationDatabaseSchemaVersion());
     print '<br /><br />';
     if (!empty($this->framework_schema_version_before)) {
         printf('Framework database schema version before upgrade: %s<br />', $this->framework_schema_version_before);
     }
     printf('Framework software supported schema version: %s<br />', $db->getFrameworkSoftwareSchemaVersion());
     printf('Framework database schema version after upgrade: %s<br />', $db->getFrameworkDatabaseSchemaVersion());
     if (($base_path = $config->getWebPath()) === true) {
         static::raiseError(get_class($config) . '"::getWebPath() returned false!');
         return false;
     }
     printf('<br /><a href="%s">Return to application</a><br />', $base_path);
     return true;
 }