public function enable($domainid)
 {
     $result = false;
     $hook = new \Innomatic\Process\Hook($this->rootDA, 'innomatic', 'application.enable');
     if ($hook->callHooks('calltime', $this, array('tenantserial' => $domainid, 'applicationid' => $this->id)) == \Innomatic\Process\Hook::RESULT_OK) {
         if ($this->id) {
             // Checks if the application exists in applications table
             //
             $modquery = $this->rootDA->execute('SELECT * FROM applications WHERE id=' . (int) $this->id);
             if ($modquery->getNumberRows() == 1) {
                 $appdata = $modquery->getFields();
                 if ($appdata['onlyextension'] != $this->rootDA->fmttrue) {
                     // Checks if the structure file still exists
                     //
                     if (file_exists($this->container->getHome() . 'core/applications/' . $appdata['appid'] . '/application.xml')) {
                         $this->appname = $appdata['appid'];
                         $domainquery = $this->rootDA->execute('SELECT * FROM domains WHERE id=' . $this->rootDA->formatText((int) $domainid));
                         $domaindata = $domainquery->getFields();
                         // Connects to the tenant database if Innomatic has been installed in ASP edition.
                         if ($this->container->getEdition() == \Innomatic\Core\InnomaticContainer::EDITION_MULTITENANT) {
                             $args['dbtype'] = $domaindata['dataaccesstype'];
                             $args['dbname'] = $domaindata['domaindaname'];
                             $args['dbhost'] = $domaindata['dataaccesshost'];
                             $args['dbport'] = $domaindata['dataaccessport'];
                             $args['dbuser'] = $domaindata['dataaccessuser'];
                             $args['dbpass'] = $domaindata['dataaccesspassword'];
                             $args['dblog'] = $this->container->getHome() . 'core/domains/' . $domaindata['domainid'] . '/log/dataaccess.log';
                             $dasnString = $args['dbtype'] . '://' . $args['dbuser'] . ':' . $args['dbpass'] . '@' . $args['dbhost'] . ':' . $args['dbport'] . '/' . $args['dbname'] . '?' . 'logfile=' . $args['dblog'];
                             $this->tenantDA = \Innomatic\Dataaccess\DataAccessFactory::getDataAccess(new \Innomatic\Dataaccess\DataAccessSourceName($dasnString));
                             $this->tenantDA->connect();
                         } else {
                             $this->tenantDA = $this->rootDA;
                         }
                         // Dependencies check
                         //
                         $this->unmetdeps = array();
                         $this->unmetsuggs = array();
                         $appdeps = new ApplicationDependencies();
                         $modenabled = $appdeps->IsEnabled($this->appname, $domaindata['domainid']);
                         $unmetdeps = $appdeps->checkDomainApplicationDependencies($this->appname, $domaindata['domainid'], ApplicationDependencies::TYPE_DEPENDENCY);
                         // Recursively enable application dependencies.
                         if (is_array($unmetdeps)) {
                             foreach ($unmetdeps as $depId => $depName) {
                                 $appQuery = $this->rootDA->execute('SELECT id FROM applications WHERE appid=' . $this->rootDA->formatText($depName));
                                 // Check if the application has been already enabled.
                                 // This happens when an application before in the dependencies list
                                 // as already enabled the current item.
                                 if ($appdeps->isEnabled($depName, $domaindata['domainid'])) {
                                     unset($unmetdeps[$depId]);
                                     continue;
                                 }
                                 // Enable the application.
                                 $app = new Application($this->rootDA, $appQuery->getFields('id'));
                                 if ($app->enable($domainid)) {
                                     unset($unmetdeps[$depId]);
                                 }
                             }
                         }
                         $unmetsuggs = $appdeps->checkDomainApplicationDependencies($this->appname, $domaindata['domainid'], ApplicationDependencies::TYPE_SUGGESTION);
                         // Suggestions check
                         //
                         if (is_array($unmetsuggs)) {
                             $this->unmetsuggs = $unmetsuggs;
                         }
                         // If dependencies are ok, go on
                         //
                         if ($unmetdeps == false and !$modenabled) {
                             $result = $this->HandleStructure($this->container->getHome() . 'core/applications/' . $appdata['appid'] . '/application.xml', Application::INSTALL_MODE_ENABLE, $this->container->getHome() . 'core/applications/' . $appdata['appid'] . '/', $domainid);
                             $modquery = $this->rootDA->execute('SELECT id FROM applications WHERE appid=' . $this->rootDA->formatText($this->appname));
                             $this->rootDA->execute('INSERT INTO applications_enabled VALUES (' . $this->id . ',' . $this->rootDA->formatText($domainid) . ',' . $this->rootDA->formatDate(time()) . ',' . $this->rootDA->formatDate(time()) . ',' . $this->rootDA->formatText($this->rootDA->fmttrue) . ')');
                             if (\Innomatic\Core\InnomaticContainer::instance('\\Innomatic\\Core\\InnomaticContainer')->getConfig()->Value('SecurityAlertOnApplicationDomainOperation') == '1') {
                                 $innomaticSecurity = new \Innomatic\Security\SecurityManager();
                                 $innomaticSecurity->SendAlert('Application ' . $appdata['appid'] . ' has been enabled to domain ' . $domaindata['domainid']);
                                 unset($innomaticSecurity);
                             }
                             if ($hook->callHooks('applicationenabled', $this, array('tenantserial' => $domainid, 'applicationid' => $this->id)) != \Innomatic\Process\Hook::RESULT_OK) {
                                 $result = false;
                             }
                         } else {
                             $this->unmetdeps = $unmetdeps;
                         }
                         //if ( $result == true ) $this->mLog->logEvent(
                         //    'Innomatic',
                         //    'Uninstalled application '.$this->appname,
                         //    \Innomatic\Logging\Logger::NOTICE
                         //);
                         $domainquery->free();
                     } else {
                         $log = $this->container->getLogger();
                         $log->logEvent('innomatic.applications.applications.enable', 'Structure file ' . $this->container->getHome() . 'core/applications/' . $appdata['appid'] . '/application.xml' . ' for application ' . $appdata['appid'] . ' was not found', \Innomatic\Logging\Logger::ERROR);
                     }
                 } else {
                     $log = $this->container->getLogger();
                     $log->logEvent('innomatic.applications.applications.enable', 'Tried to enable application ' . $appdata['appid'] . ', but it is an extension only application', \Innomatic\Logging\Logger::ERROR);
                 }
             } else {
                 $log = $this->container->getLogger();
                 $log->logEvent('innomatic.applications.applications.enable', 'A application with id ' . $this->id . ' was not found in applications table', \Innomatic\Logging\Logger::ERROR);
             }
             $modquery->free();
         } else {
             $log = $this->container->getLogger();
             $log->logEvent('innomatic.applications.applications.enable', 'Empty application id', \Innomatic\Logging\Logger::ERROR);
         }
     }
     return $result;
 }