Exemplo n.º 1
0
 public function install($tmpfilepath, $updateOnce = false)
 {
     // Checks if the given path is a directory. This may happen when not
     // giving a file to the application installation page.
     if (is_dir($tmpfilepath)) {
         return false;
     }
     $result = false;
     $innomatic = $this->container;
     if ($innomatic->getState() == \Innomatic\Core\InnomaticContainer::STATE_DEBUG) {
         $innomatic->getLoadTimer()->Mark('applicationinstallstart');
     }
     if (file_exists($tmpfilepath)) {
         // Moves temp file to applications repository and extracts it
         //
         $fname = $this->container->getHome() . 'core/applications/' . basename($tmpfilepath);
         @copy($tmpfilepath, $fname);
         $basetmpdir = $tmpdir = $this->container->getHome() . 'core/temp/appinst/' . md5(microtime());
         @mkdir($tmpdir, 0755);
         $olddir = getcwd();
         @chdir($tmpdir);
         if (substr($fname, -4) == '.zip') {
         } else {
             try {
                 $appArchive = new \PharData($fname);
                 $tarFileName = substr($fname, 0, strpos($fname, '.')) . '.tar';
                 if (file_exists($tarFileName)) {
                     unlink($tarFileName);
                 }
                 $appArchive->decompress();
             } catch (\BadMethodCallException $e) {
             }
             try {
                 $appArchive->extractTo($tmpdir);
             } catch (Exception $e) {
             }
         }
         // Checks if the files are into a directory instead of the root
         //
         if (!@is_dir($tmpdir . '/setup')) {
             $dhandle = opendir($tmpdir);
             while (false != ($file = readdir($dhandle))) {
                 if ($file != '.' && $file != '..' && (is_dir($tmpdir . '/' . $file . '/setup') or is_dir($tmpdir . '/' . $file . '/innomatic/setup'))) {
                     if (is_dir($tmpdir . '/' . $file . '/setup')) {
                         $tmpdir = $tmpdir . '/' . $file;
                     } else {
                         $tmpdir = $tmpdir . '/' . $file . '/innomatic';
                     }
                     break;
                 }
             }
             closedir($dhandle);
         }
         $this->basedir = $tmpdir;
         // Checks for definition and structure files
         //
         if (file_exists($tmpdir . '/setup/bundle.ini')) {
             $applicationsArray = file($tmpdir . '/setup/bundle.ini');
             $result = true;
             while (list(, $application) = each($applicationsArray)) {
                 $application = trim($application);
                 if (strlen($application) and file_exists($tmpdir . '/applications/' . $application)) {
                     $tempApplication = new Application($this->rootda);
                     if (!$tempApplication->Install($tmpdir . '/applications/' . $application)) {
                         $result = false;
                     }
                 }
             }
         } elseif (file_exists($tmpdir . '/setup/application.xml')) {
             $genconfig = $this->parseApplicationDefinition($tmpdir . '/setup/application.xml');
             $this->appname = $genconfig['ApplicationIdName'];
             // Checks if the application has been already installed
             //
             $tmpquery = $this->rootda->execute('SELECT id,appfile FROM applications WHERE appid=' . $this->rootda->formatText($this->appname));
             if (!$tmpquery->getNumberRows()) {
                 // Application is new, so it will be installed
                 //
                 // Dependencies check
                 //
                 $this->unmetdeps = array();
                 $this->unmetsuggs = array();
                 $appdeps = new ApplicationDependencies();
                 $deps = $appdeps->explodeDependencies($genconfig['ApplicationDependencies']);
                 $suggs = $appdeps->explodeDependencies($genconfig['ApplicationSuggestions']);
                 if ($deps != false) {
                     $this->unmetdeps = $appdeps->checkApplicationDependencies(0, '', $deps);
                 } else {
                     $this->unmetdeps = false;
                 }
                 // Suggestions check
                 //
                 if ($suggs != false) {
                     $unmetsuggs = $appdeps->checkApplicationDependencies(0, '', $suggs);
                     if (is_array($unmetsuggs)) {
                         $this->unmetsuggs = $unmetsuggs;
                     }
                 }
                 // If dependencies are ok, go on
                 //
                 if ($this->unmetdeps == false) {
                     // Gets serial number for the application
                     //
                     $this->serial = $this->rootda->getNextSequenceValue('applications_id_seq');
                     $this->rootda->execute('INSERT INTO applications VALUES ( ' . $this->serial . ',' . $this->rootda->formatText($genconfig['ApplicationIdName']) . ',' . $this->rootda->formatText($genconfig['ApplicationVersion']) . ',' . $this->rootda->formatText($genconfig['ApplicationDate']) . ',' . $this->rootda->formatText($genconfig['ApplicationDescription']) . ',' . $this->rootda->formatText(basename($tmpfilepath)) . ',' . $this->rootda->formatText($this->rootda->fmtfalse) . ',' . $this->rootda->formatText($genconfig['ApplicationAuthor']) . ',' . $this->rootda->formatText($genconfig['ApplicationAuthorEmail']) . ',' . $this->rootda->formatText($genconfig['ApplicationAuthorWeb']) . ',' . $this->rootda->formatText($genconfig['ApplicationSupportEmail']) . ',' . $this->rootda->formatText($genconfig['ApplicationBugsEmail']) . ',' . $this->rootda->formatText($genconfig['ApplicationCopyright']) . ',' . $this->rootda->formatText($genconfig['ApplicationLicense']) . ',' . $this->rootda->formatText($genconfig['ApplicationLicenseFile']) . ',' . $this->rootda->formatText($genconfig['ApplicationChangesFile']) . ',' . $this->rootda->formatText($genconfig['ApplicationMaintainer']) . ',' . $this->rootda->formatText($genconfig['ApplicationMaintainerEmail']) . ',' . $this->rootda->formatText($genconfig['ApplicationCategory']) . ',' . $this->rootda->formatText($genconfig['ApplicationIconFile']) . ')');
                     // Application dir creation
                     //
                     @mkdir($this->container->getHome() . 'core/applications/' . $genconfig['ApplicationIdName'], 0755);
                     // Defs files
                     //
                     if ($dhandle = @opendir($tmpdir . '/setup')) {
                         while (false != ($file = readdir($dhandle))) {
                             if ($file != '.' && $file != '..' && is_file($tmpdir . '/setup/' . $file)) {
                                 @copy($tmpdir . '/setup/' . $file, $this->container->getHome() . 'core/applications/' . $genconfig['ApplicationIdName'] . '/' . $file);
                             }
                         }
                         closedir($dhandle);
                     }
                     // Adds applications dependencies
                     //
                     $appdeps->addDependenciesArray($genconfig['ApplicationIdName'], $deps, ApplicationDependencies::TYPE_DEPENDENCY);
                     $appdeps->addDependenciesArray($genconfig['ApplicationIdName'], $suggs, ApplicationDependencies::TYPE_SUGGESTION);
                     $this->setOptions(explode(',', trim($genconfig['ApplicationOptions'], ' ,')));
                     $this->HandleStructure($tmpdir . '/setup/application.xml', Application::INSTALL_MODE_INSTALL, $tmpdir);
                     if (strlen($genconfig['ApplicationLicenseFile']) and file_exists($tmpdir . '/setup/' . $genconfig['ApplicationLicenseFile'])) {
                         @copy($tmpdir . '/setup/' . $genconfig['ApplicationLicenseFile'], $this->container->getHome() . 'core/applications/' . $genconfig['ApplicationIdName'] . '/' . $genconfig['ApplicationLicenseFile']);
                     }
                     if (strlen($genconfig['ApplicationChangesFile']) and file_exists($tmpdir . '/setup/' . $genconfig['ApplicationChangesFile'])) {
                         @copy($tmpdir . '/setup/' . $genconfig['ApplicationChangesFile'], $this->container->getHome() . 'core/applications/' . $genconfig['ApplicationIdName'] . '/' . $genconfig['ApplicationChangesFile']);
                     }
                     if (strlen($genconfig['ApplicationIconFile']) and file_exists($tmpdir . '/setup/' . $genconfig['ApplicationIconFile'])) {
                         @copy($tmpdir . '/setup/' . $genconfig['ApplicationIconFile'], $this->container->getHome() . 'core/applications/' . $genconfig['ApplicationIdName'] . '/' . $genconfig['ApplicationIconFile']);
                     }
                     // Checks if it is an extension application
                     //
                     $genconfig = $this->parseApplicationDefinition($tmpdir . '/setup/application.xml');
                     $ext = $this->rootda->fmtfalse;
                     if ($genconfig['ApplicationIsExtension'] == 'y') {
                         $ext = $this->rootda->fmttrue;
                         $this->onlyextension = true;
                     } elseif ($genconfig['ApplicationIsExtension'] == 'n') {
                         $ext = $this->rootda->fmtfalse;
                         $this->onlyextension = false;
                     } elseif ($this->onlyextension) {
                         $ext = $this->rootda->fmttrue;
                     }
                     $this->rootda->execute('UPDATE applications SET onlyextension=' . $this->rootda->formatText($ext) . ' WHERE appid=' . $this->rootda->formatText($this->appname));
                     $result = true;
                     if ($this->container->getConfig()->Value('SecurityAlertOnApplicationOperation') == '1') {
                         $innomaticSecurity = new \Innomatic\Security\SecurityManager();
                         $innomaticSecurity->SendAlert('Application ' . $this->appname . ' has been installed');
                         unset($innomaticSecurity);
                     }
                     if ($result == true) {
                         if ($this->container->getEdition() == \Innomatic\Core\InnomaticContainer::EDITION_SINGLETENANT and $this->appname != 'innomatic' and $ext != $this->rootda->fmttrue) {
                             $domainsQuery = \Innomatic\Core\InnomaticContainer::instance('\\Innomatic\\Core\\InnomaticContainer')->getDataAccess()->execute('SELECT id FROM domains');
                             if ($domainsQuery->getNumberRows()) {
                                 $this->Enable($domainsQuery->getFields('id'));
                             }
                         }
                         $log = $this->container->getLogger();
                         $log->logEvent('Innomatic', 'Installed application ' . $this->appname, \Innomatic\Logging\Logger::NOTICE);
                     }
                 }
             } else {
                 $appdata = $tmpquery->getFields();
                 $this->serial = $appdata['id'];
                 // Application will be updated
                 //
                 if ($this->serial) {
                     // Dependencies check
                     //
                     $this->unmetdeps = array();
                     $this->unmetsuggs = array();
                     $appdeps = new ApplicationDependencies();
                     $deps = $appdeps->explodeDependencies($genconfig['ApplicationDependencies']);
                     $suggs = $appdeps->explodeDependencies($genconfig['ApplicationSuggestions']);
                     if ($deps != false) {
                         $this->unmetdeps = $appdeps->checkApplicationDependencies(0, '', $deps);
                     } else {
                         $this->unmetdeps = false;
                     }
                     // Suggestions check
                     //
                     if ($suggs != false) {
                         $unmetsuggs = $appdeps->checkApplicationDependencies(0, '', $suggs);
                         if (is_array($unmetsuggs)) {
                             $this->unmetsuggs = $unmetsuggs;
                         }
                     }
                     // If dependencies are ok, go on
                     //
                     if ($this->unmetdeps == false) {
                         // Creates lock file
                         //
                         touch($this->container->getHome() . 'core/temp/upgrading_system_lock');
                         // :WARNING: evil 20020506: possible problems on Windows systems
                         // It has a 'permission denied'.
                         // Removes old application file
                         //
                         if (basename($fname) != $appdata['appfile'] and file_exists($this->container->getHome() . 'core/applications/' . $appdata['appfile'])) {
                             @unlink($this->container->getHome() . 'core/applications/' . $appdata['appfile']);
                         }
                         // Updates applications table
                         //
                         $this->rootda->execute('UPDATE applications SET appversion=' . $this->rootda->formatText($genconfig['ApplicationVersion']) . ', appdate=' . $this->rootda->formatText($genconfig['ApplicationDate']) . ', appdesc=' . $this->rootda->formatText($genconfig['ApplicationDescription']) . ', appfile=' . $this->rootda->formatText(basename($tmpfilepath)) . ', author=' . $this->rootda->formatText($genconfig['ApplicationAuthor']) . ', authoremail=' . $this->rootda->formatText($genconfig['ApplicationAuthorEmail']) . ', authorsite=' . $this->rootda->formatText($genconfig['ApplicationAuthorWeb']) . ', supportemail=' . $this->rootda->formatText($genconfig['ApplicationSupportEmail']) . ', bugsemail=' . $this->rootda->formatText($genconfig['ApplicationBugsEmail']) . ', copyright=' . $this->rootda->formatText($genconfig['ApplicationCopyright']) . ', license=' . $this->rootda->formatText($genconfig['ApplicationLicense']) . ', licensefile=' . $this->rootda->formatText($genconfig['ApplicationLicenseFile']) . ', changesfile=' . $this->rootda->formatText($genconfig['ApplicationChangesFile']) . ', maintainer=' . $this->rootda->formatText($genconfig['ApplicationMaintainer']) . ', maintaineremail=' . $this->rootda->formatText($genconfig['ApplicationMaintainerEmail']) . ', category=' . $this->rootda->formatText($genconfig['ApplicationCategory']) . ', iconfile=' . $this->rootda->formatText($genconfig['ApplicationIconFile']) . ' WHERE id=' . (int) $this->serial);
                         $genconfig = $this->parseApplicationDefinition($tmpdir . '/setup/application.xml');
                         // Script files - only before handlestructure
                         //
                         if ($dhandle = @opendir($tmpdir . '/setup')) {
                             while (false != ($file = readdir($dhandle))) {
                                 if ($file != '.' and $file != '..' and $file != 'application.xml' and is_file($tmpdir . '/setup/' . $file)) {
                                     @copy($tmpdir . '/setup/' . $file, $this->container->getHome() . 'core/applications/' . $genconfig['ApplicationIdName'] . '/' . $file);
                                 }
                             }
                             closedir($dhandle);
                         }
                         $this->HandleStructure($tmpdir . '/setup/application.xml', Application::INSTALL_MODE_UPDATE, $tmpdir);
                         if (strlen($genconfig['ApplicationLicenseFile']) and file_exists($tmpdir . '/setup/' . $genconfig['ApplicationLicenseFile'])) {
                             @copy($tmpdir . '/setup/' . $genconfig['ApplicationLicenseFile'], $this->container->getHome() . 'core/applications/' . $genconfig['ApplicationIdName'] . '/' . $genconfig['ApplicationLicenseFile']);
                         }
                         if (strlen($genconfig['ApplicationChangesFile']) and file_exists($tmpdir . '/setup/' . $genconfig['ApplicationChangesFile'])) {
                             @copy($tmpdir . '/setup/' . $genconfig['ApplicationChangesFile'], $this->container->getHome() . 'core/applications/' . $genconfig['ApplicationIdName'] . '/' . $genconfig['ApplicationChangesFile']);
                         }
                         if (strlen($genconfig['ApplicationIconFile']) and file_exists($tmpdir . '/setup/' . $genconfig['ApplicationIconFile'])) {
                             @copy($tmpdir . '/setup/' . $genconfig['ApplicationIconFile'], $this->container->getHome() . 'core/applications/' . $genconfig['ApplicationIdName'] . '/' . $genconfig['ApplicationIconFile']);
                         }
                         // setup files - only after handlestructure
                         //
                         @copy($tmpdir . '/setup/application.xml', $this->container->getHome() . 'core/applications/' . $genconfig['ApplicationIdName'] . '/application.xml');
                         // Checks if it is an extension application
                         //
                         $ext = $this->rootda->fmtfalse;
                         if ($genconfig['ApplicationIsExtension'] == 'y') {
                             $ext = $this->rootda->fmttrue;
                             $this->onlyextension = true;
                         } elseif ($genconfig['ApplicationIsExtension'] == 'n') {
                             $ext = $this->rootda->fmtfalse;
                             $this->onlyextension = false;
                         } elseif ($this->onlyextension) {
                             $ext = $this->rootda->fmttrue;
                         }
                         $this->rootda->execute('UPDATE applications SET onlyextension=' . $this->rootda->formatText($ext) . ' WHERE appid=' . $this->rootda->formatText($this->appname));
                         $this->setOptions(explode(',', trim($genconfig['ApplicationOptions'], ' ,')));
                         if ($this->appname != 'innomatic') {
                             // Remove old dependencies
                             //
                             $appdeps->removeAllDependencies($this->serial);
                             // Adds new Applications dependencies
                             //
                             $appdeps->addDependenciesArray($genconfig['ApplicationIdName'], $deps, ApplicationDependencies::TYPE_DEPENDENCY);
                             $appdeps->addDependenciesArray($genconfig['ApplicationIdName'], $suggs, ApplicationDependencies::TYPE_SUGGESTION);
                         }
                         $result = true;
                         if (function_exists('apc_reset_cache')) {
                             apc_reset_cache();
                         }
                         if ($updateOnce == false) {
                             $this->Install($tmpfilepath, true);
                             // Removes lock file
                             //
                             unlink($this->container->getHome() . 'core/temp/upgrading_system_lock');
                             if (\Innomatic\Core\InnomaticContainer::instance('\\Innomatic\\Core\\InnomaticContainer')->getConfig()->Value('SecurityAlertOnApplicationOperation') == '1') {
                                 $innomaticSecurity = new \Innomatic\Security\SecurityManager();
                                 $innomaticSecurity->SendAlert('Application ' . $this->appname . ' has been updated');
                                 unset($innomaticSecurity);
                             }
                             if ($result == true) {
                                 $log = $this->container->getLogger();
                                 $log->logEvent('Innomatic', 'Updated application ' . $this->appname, \Innomatic\Logging\Logger::NOTICE);
                             }
                         }
                     }
                     /*
                     else $this->mLog->logEvent( 'innomatic.applications.applications.install',
                     'Structure definition file for application '.$this->appname.
                     ' does not exists', \Innomatic\Logging\Logger::ERROR );
                     */
                 } else {
                     $log = $this->container->getLogger();
                     $log->logEvent('innomatic.applications.applications.install', 'Empty application serial', \Innomatic\Logging\Logger::ERROR);
                 }
             }
         } else {
             $log = $this->container->getLogger();
             if (!file_exists($tmpdir . '/setup/application.xml')) {
                 $log->logEvent('innomatic.applications.applications.install', 'Application structure file ' . $tmpdir . '/setup/application.xml' . ' not found', \Innomatic\Logging\Logger::ERROR);
             }
         }
         // Cleans up temp stuff
         //
         @chdir($olddir);
         \Innomatic\Io\Filesystem\DirectoryUtils::unlinkTree($basetmpdir);
         if (file_exists($tmpfilepath)) {
             @unlink($tmpfilepath);
         }
     } else {
         if (!file_exists($tmpfilepath)) {
             $log = $this->container->getLogger();
             $log->logEvent('innomatic.applications.applications.install', 'Temporary application file (' . $tmpfilepath . ') does not exists', \Innomatic\Logging\Logger::ERROR);
         }
     }
     if ($innomatic->getState() == \Innomatic\Core\InnomaticContainer::STATE_DEBUG) {
         $innomatic->getLoadTimer()->Mark('applicationinstallend');
         $log = $this->container->getLogger();
         $log->logEvent('innomatic.applications.application.install', 'Application installation load time: ' . $innomatic->getLoadTimer()->getSectionLoad('applicationinstallend'), \Innomatic\Logging\Logger::DEBUG);
     }
     return $result;
 }
Exemplo n.º 2
0
 function Install($tmpfilepath, $updateOnce = false)
 {
     $result = FALSE;
     import('com.solarix.ampoliros.core.Ampoliros');
     $amp = Ampoliros::instance('Ampoliros');
     if ($amp->GetState() == Ampoliros::STATE_DEBUG) {
         $GLOBALS['gEnv']['runtime']['debug']['loadtime']->Mark('moduleinstallstart');
     }
     if (file_exists($tmpfilepath)) {
         import('carthag.io.archive.Archive');
         // Moves temp file to modules repository and extracts it
         //
         $fname = MODULE_PATH . basename($tmpfilepath);
         @copy($tmpfilepath, $fname);
         $basetmpdir = $tmpdir = TMP_PATH . 'modinst/' . md5(microtime());
         @mkdir($tmpdir, 0755);
         $olddir = getcwd();
         @chdir($tmpdir);
         //@system( escapeshellcmd( 'tar zxf '.$fname ) );
         $archive_format = ARCHIVE_TGZ;
         if (substr($fname, -4) == '.zip') {
             $archive_format = ARCHIVE_ZIP;
         }
         $mod_archive = new Archive($fname, $archive_format);
         $mod_archive->Extract($tmpdir);
         // Checks if the files are into a directory instead of the root
         //
         if (!@is_dir($tmpdir . '/defs')) {
             $dhandle = opendir($tmpdir);
             while (FALSE != ($file = readdir($dhandle))) {
                 if ($file != '.' && $file != '..' && is_dir($tmpdir . '/' . $file . '/defs')) {
                     $tmpdir = $tmpdir . '/' . $file;
                 }
             }
             closedir($dhandle);
         }
         $this->basedir = $tmpdir;
         // Checks for definition and structure files
         //
         if (file_exists($tmpdir . '/defs/' . Module::BUNDLEDEF_FILE)) {
             $modules_array = file($tmpdir . '/defs/' . Module::BUNDLEDEF_FILE);
             $result = TRUE;
             while (list(, $module) = each($modules_array)) {
                 $module = trim($module);
                 if (strlen($module) and file_exists($tmpdir . '/modules/' . $module)) {
                     $temp_module = new Module($this->ampdb);
                     if (!$temp_module->Install($tmpdir . '/modules/' . $module)) {
                         $result = FALSE;
                     }
                 }
             }
         } else {
             if (file_exists($tmpdir . '/defs/' . Module::STRUCTURE_FILE) and file_exists($tmpdir . '/defs/' . Module::GENERALDEF_FILE)) {
                 $genconfig = new ConfigFile($tmpdir . '/defs/' . Module::GENERALDEF_FILE);
                 $this->modname = $genconfig->Value('MODULEIDNAME');
                 // Checks if the module has been already installed
                 //
                 $tmpquery = $this->ampdb->Execute('SELECT id,modfile FROM modules WHERE modid=' . $this->ampdb->Format_Text($this->modname));
                 if (!$tmpquery->NumRows()) {
                     // Module is new, so it will be installed
                     //
                     // Dependencies check
                     //
                     $this->unmetdeps = array();
                     $this->unmetsuggs = array();
                     $moddeps = new ModuleDep($this->ampdb);
                     $deps = $moddeps->ExplodeDeps($genconfig->Value('MODULEDEPENDENCIES'));
                     $suggs = $moddeps->ExplodeDeps($genconfig->Value('MODULESUGGESTIONS'));
                     if ($deps != FALSE) {
                         $this->unmetdeps = $moddeps->CheckModuleDeps(0, '', $deps);
                     } else {
                         $this->unmetdeps == FALSE;
                     }
                     // Suggestions check
                     //
                     if ($suggs != FALSE) {
                         $unmetsuggs = $moddeps->CheckModuleDeps(0, '', $suggs);
                         if (is_array($unmetsuggs)) {
                             $this->unmetsuggs = $unmetsuggs;
                         }
                     }
                     // If dependencies are ok, go on
                     //
                     if ($this->unmetdeps == FALSE) {
                         // Gets serial number for the module
                         //
                         $this->serial = $this->ampdb->NextSeqValue('modules_id_seq');
                         $this->ampdb->Execute('INSERT INTO modules VALUES ( ' . $this->serial . ',' . $this->ampdb->Format_Text($genconfig->Value('MODULEIDNAME')) . ',' . $this->ampdb->Format_Text($genconfig->Value('MODULEVERSION')) . ',' . $this->ampdb->Format_Text($genconfig->Value('MODULEDATE')) . ',' . $this->ampdb->Format_Text($genconfig->Value('MODULEDESCRIPTION')) . ',' . $this->ampdb->Format_Text(basename($tmpfilepath)) . ',' . $this->ampdb->Format_Text($this->ampdb->fmtfalse) . ',' . $this->ampdb->Format_Text($genconfig->Value('MODULE_AUTHOR')) . ',' . $this->ampdb->Format_Text($genconfig->Value('MODULE_AUTHOR_EMAIL')) . ',' . $this->ampdb->Format_Text($genconfig->Value('MODULE_AUTHOR_SITE')) . ',' . $this->ampdb->Format_Text($genconfig->Value('MODULE_SUPPORT_EMAIL')) . ',' . $this->ampdb->Format_Text($genconfig->Value('MODULE_BUGS_EMAIL')) . ',' . $this->ampdb->Format_Text($genconfig->Value('MODULE_COPYRIGHT')) . ',' . $this->ampdb->Format_Text($genconfig->Value('MODULE_LICENSE')) . ',' . $this->ampdb->Format_Text($genconfig->Value('MODULE_LICENSE_FILE')) . ',' . $this->ampdb->Format_Text($genconfig->Value('MODULE_MAINTAINER')) . ',' . $this->ampdb->Format_Text($genconfig->Value('MODULE_MAINTAINER_EMAIL')) . ',' . $this->ampdb->Format_Text($genconfig->Value('MODULE_CATEGORY')) . ')');
                         // Module dir creation
                         //
                         @mkdir(MODULE_PATH . $genconfig->Value('MODULEIDNAME'), 0755);
                         // Defs files
                         //
                         if ($dhandle = @opendir($tmpdir . '/defs')) {
                             while (FALSE != ($file = readdir($dhandle))) {
                                 if ($file != '.' && $file != '..' && is_file($tmpdir . '/defs/' . $file)) {
                                     @copy($tmpdir . '/defs/' . $file, MODULE_PATH . $genconfig->Value('MODULEIDNAME') . '/' . $file);
                                 }
                             }
                             closedir($dhandle);
                         }
                         // Adds modules dependencies
                         //
                         $moddeps->AddDepsArray($genconfig->Value('MODULEIDNAME'), $deps, DEPTYPE_DEP);
                         $moddeps->AddDepsArray($genconfig->Value('MODULEIDNAME'), $suggs, DEPTYPE_SUGG);
                         $this->SetSubModules(explode(',', trim($genconfig->Value('MODULE_SUBMODULES'), ' ,')));
                         $this->HandleStructure($tmpdir . '/defs/' . Module::STRUCTURE_FILE, Module::INSTALL_MODE_INSTALL, $tmpdir);
                         if (strlen($genconfig->Value('MODULE_LICENSE_FILE')) and file_exists($tmpdir . '/' . $genconfig->Value('MODULE_LICENSE_FILE'))) {
                             @copy($tmpdir . '/' . $genconfig->Value('MODULE_LICENSE_FILE'), MODULE_PATH . $genconfig->Value('MODULEIDNAME') . '/' . $genconfig->Value('MODULE_LICENSE_FILE'));
                         }
                         // Checks if it is an extension module
                         //
                         $genconfig = new ConfigFile($tmpdir . '/defs/' . Module::GENERALDEF_FILE);
                         $ext = $this->ampdb->fmtfalse;
                         if ($genconfig->Value('ONLYEXTENSION') == 'y') {
                             $ext = $this->ampdb->fmttrue;
                             $this->onlyextension = TRUE;
                         } else {
                             if ($genconfig->Value('ONLYEXTENSION') == 'n') {
                                 $ext = $this->ampdb->fmtfalse;
                                 $this->onlyextension = FALSE;
                             } else {
                                 if ($this->onlyextension) {
                                     $ext = $this->ampdb->fmttrue;
                                 }
                             }
                         }
                         $this->ampdb->Execute('UPDATE modules SET onlyextension=' . $this->ampdb->Format_Text($ext) . ' WHERE modid=' . $this->ampdb->Format_Text($this->modname));
                         $result = TRUE;
                         if ($GLOBALS['gEnv']['core']['config']->Value('ALERT_ON_MODULE_OPERATION') == '1') {
                             import('com.solarix.ampoliros.security.SecurityLayer');
                             $amp_security = new SecurityLayer();
                             $amp_security->SendAlert('Module ' . $this->modname . ' has been installed');
                             unset($amp_security);
                         }
                         if ($result == true) {
                             if ($GLOBALS['gEnv']['core']['edition'] == AMP_EDITION_ENTERPRISE and $this->modname != 'ampoliros' and $ext != $this->ampdb->fmttrue) {
                                 $sites_query = $GLOBALS['gEnv']['root']['db']->Execute('SELECT id FROM sites');
                                 if ($sites_query->NumRows()) {
                                     $this->Enable($sites_query->Fields('id'));
                                 }
                             }
                             import('com.solarix.ampoliros.io.log.Logger');
                             $log = new Logger(AMP_LOG);
                             $log->LogEvent('Ampoliros', 'Installed module ' . $this->modname, LOGGER_NOTICE);
                         }
                     }
                 } else {
                     $moddata = $tmpquery->Fields();
                     $this->serial = $moddata['id'];
                     // Module will be updated
                     //
                     if ($this->serial) {
                         // Dependencies check
                         //
                         $this->unmetdeps = array();
                         $this->unmetsuggs = array();
                         $moddeps = new ModuleDep($this->ampdb);
                         $deps = $moddeps->ExplodeDeps($genconfig->Value('MODULEDEPENDENCIES'));
                         $suggs = $moddeps->ExplodeDeps($genconfig->Value('MODULESUGGESTIONS'));
                         if ($deps != FALSE) {
                             $this->unmetdeps = $moddeps->CheckModuleDeps(0, '', $deps);
                         } else {
                             $this->unmetdeps == FALSE;
                         }
                         // Suggestions check
                         //
                         if ($suggs != FALSE) {
                             $unmetsuggs = $moddeps->CheckModuleDeps(0, '', $suggs);
                             if (is_array($unmetsuggs)) {
                                 $this->unmetsuggs = $unmetsuggs;
                             }
                         }
                         // If dependencies are ok, go on
                         //
                         if ($this->unmetdeps == FALSE) {
                             // Creates lock file
                             //
                             touch(TMP_PATH . '.upgrading_system');
                             // :WARNING: evil 20020506: possible problems on Windows systems
                             // It has a 'permission denied'.
                             // Removes old module file
                             //
                             if (basename($fname) != $moddata['modfile'] and file_exists(MODULE_PATH . $moddata['modfile'])) {
                                 @unlink(MODULE_PATH . $moddata['modfile']);
                             }
                             // Updates modules table
                             //
                             $this->ampdb->Execute('UPDATE modules SET modversion=' . $this->ampdb->Format_Text($genconfig->Value('MODULEVERSION')) . ', moddate=' . $this->ampdb->Format_Text($genconfig->Value('MODULEDATE')) . ', moddesc=' . $this->ampdb->Format_Text($genconfig->Value('MODULEDESCRIPTION')) . ', modfile=' . $this->ampdb->Format_Text(basename($tmpfilepath)) . ', author=' . $this->ampdb->Format_Text($genconfig->Value('MODULE_AUTHOR')) . ', authoremail=' . $this->ampdb->Format_Text($genconfig->Value('MODULE_AUTHOR_EMAIL')) . ', authorsite=' . $this->ampdb->Format_Text($genconfig->Value('MODULE_AUTHOR_SITE')) . ', supportemail=' . $this->ampdb->Format_Text($genconfig->Value('MODULE_SUPPORT_EMAIL')) . ', bugsemail=' . $this->ampdb->Format_Text($genconfig->Value('MODULE_BUGS_EMAIL')) . ', copyright=' . $this->ampdb->Format_Text($genconfig->Value('MODULE_COPYRIGHT')) . ', license=' . $this->ampdb->Format_Text($genconfig->Value('MODULE_LICENSE')) . ', licensefile=' . $this->ampdb->Format_Text($genconfig->Value('MODULE_LICENSE_FILE')) . ', maintainer=' . $this->ampdb->Format_Text($genconfig->Value('MODULE_MAINTAINER')) . ', maintaineremail=' . $this->ampdb->Format_Text($genconfig->Value('MODULE_MAINTAINER_EMAIL')) . ', category=' . $this->ampdb->Format_Text($genconfig->Value('MODULE_CATEGORY')) . ' WHERE id=' . (int) $this->serial);
                             $genconfig = new ConfigFile($tmpdir . '/defs/' . Module::GENERALDEF_FILE);
                             // Script files - only before handlestructure
                             //
                             if ($dhandle = @opendir($tmpdir . '/defs')) {
                                 while (FALSE != ($file = readdir($dhandle))) {
                                     if ($file != '.' and $file != '..' and $file != Module::STRUCTURE_FILE and $file != Module::GENERALDEF_FILE and is_file($tmpdir . '/defs/' . $file)) {
                                         @copy($tmpdir . '/defs/' . $file, MODULE_PATH . $genconfig->Value('MODULEIDNAME') . '/' . $file);
                                     }
                                 }
                                 closedir($dhandle);
                             }
                             $this->HandleStructure($tmpdir . '/defs/' . Module::STRUCTURE_FILE, Module::INSTALL_MODE_UPDATE, $tmpdir);
                             if (strlen($genconfig->Value('MODULE_LICENSE_FILE')) and file_exists($tmpdir . '/' . $genconfig->Value('MODULE_LICENSE_FILE'))) {
                                 @copy($tmpdir . '/' . $genconfig->Value('MODULE_LICENSE_FILE'), MODULE_PATH . $genconfig->Value('MODULEIDNAME') . '/' . $genconfig->Value('MODULE_LICENSE_FILE'));
                             }
                             // Defs files - only after handlestructure
                             //
                             @copy($tmpdir . '/defs/' . Module::STRUCTURE_FILE, MODULE_PATH . $genconfig->Value('MODULEIDNAME') . '/' . Module::STRUCTURE_FILE);
                             @copy($tmpdir . '/defs/' . Module::GENERALDEF_FILE, MODULE_PATH . $genconfig->Value('MODULEIDNAME') . '/' . Module::GENERALDEF_FILE);
                             // Checks if it is an extension module
                             //
                             $ext = $this->ampdb->fmtfalse;
                             if ($genconfig->Value('ONLYEXTENSION') == 'y') {
                                 $ext = $this->ampdb->fmttrue;
                                 $this->onlyextension = TRUE;
                             } else {
                                 if ($genconfig->Value('ONLYEXTENSION') == 'n') {
                                     $ext = $this->ampdb->fmtfalse;
                                     $this->onlyextension = FALSE;
                                 } else {
                                     if ($this->onlyextension) {
                                         $ext = $this->ampdb->fmttrue;
                                     }
                                 }
                             }
                             $this->ampdb->Execute('UPDATE modules SET onlyextension=' . $this->ampdb->Format_Text($ext) . ' WHERE modid=' . $this->ampdb->Format_Text($this->modname));
                             $this->SetSubModules(explode(',', trim($genconfig->Value('MODULE_SUBMODULES'), ' ,')));
                             if ($this->modname != 'ampoliros') {
                                 // Remove old dependencies
                                 //
                                 $moddeps->RemAllDep($this->serial);
                                 // Adds new modules dependencies
                                 //
                                 $moddeps->AddDepsArray($genconfig->Value('MODULEIDNAME'), $deps, DEPTYPE_DEP);
                                 $moddeps->AddDepsArray($genconfig->Value('MODULEIDNAME'), $suggs, DEPTYPE_SUGG);
                             }
                             $result = TRUE;
                             if (function_exists('apc_reset_cache')) {
                                 apc_reset_cache();
                             }
                             if ($updateOnce == FALSE) {
                                 $this->Install($tmpfilepath, true);
                                 // Removes lock file
                                 //
                                 unlink(TMP_PATH . '.upgrading_system');
                                 if ($GLOBALS['gEnv']['core']['config']->Value('ALERT_ON_MODULE_OPERATION') == '1') {
                                     Carthag::import('com.solarix.ampoliros.security.SecurityLayer');
                                     $amp_security = new SecurityLayer();
                                     $amp_security->SendAlert('Module ' . $this->modname . ' has been updated');
                                     unset($amp_security);
                                 }
                                 if ($result == TRUE) {
                                     import('com.solarix.ampoliros.io.log.Logger');
                                     $log = new Logger(AMP_LOG);
                                     $log->LogEvent('Ampoliros', 'Updated module ' . $this->modname, LOGGER_NOTICE);
                                 }
                             }
                         }
                         /*
                         else $this->mLog->LogEvent( 'ampoliros.modules_library.modules_class.install',
                         'Structure definition file for module '.$this->modname.' does not exists', LOGGER_ERROR );
                         */
                     } else {
                         import('com.solarix.ampoliros.io.log.Logger');
                         $log = new Logger(AMP_LOG);
                         $log->LogEvent('ampoliros.modules_library.modules_class.install', 'Empty module serial', LOGGER_ERROR);
                     }
                 }
             } else {
                 import('com.solarix.ampoliros.io.log.Logger');
                 $log = new Logger(AMP_LOG);
                 if (!file_exists($tmpdir . '/defs/' . Module::STRUCTURE_FILE)) {
                     $log->LogEvent('ampoliros.modules_library.modules_class.install', 'Module structure file ' . $tmpdir . '/defs/' . Module::STRUCTURE_FILE . ' not found', LOGGER_ERROR);
                 }
                 if (!file_exists($tmpdir . '/defs/' . Module::GENERALDEF_FILE)) {
                     $log->LogEvent('ampoliros.modules_library.modules_class.install', 'Module definition file ' . $tmpdir . '/defs/' . Module::GENERALDEF_FILE . ' not found', LOGGER_ERROR);
                 }
             }
         }
         // Cleans up temp stuff
         //
         @chdir($olddir);
         RecRemoveDir($basetmpdir);
         if (file_exists($tmpfilepath)) {
             @unlink($tmpfilepath);
         }
     } else {
         if (!file_exists($tmpfilepath)) {
             import('com.solarix.ampoliros.io.log.Logger');
             $log = new Logger(AMP_LOG);
             $log->LogEvent('ampoliros.modules_library.modules_class.install', 'Temporary module file (' . $tmpfilepath . ') does not exists', LOGGER_ERROR);
         }
     }
     if ($amp->getState() == Ampoliros::STATE_DEBUG) {
         $GLOBALS['gEnv']['runtime']['debug']['loadtime']->Mark('moduleinstallend');
         import('com.solarix.ampoliros.io.log.Logger');
         $log = new Logger(AMP_LOG);
         $log->LogEvent('ampoliros.modules_library.module_class.install', 'Module installation load time: ' . $GLOBALS['gEnv']['runtime']['debug']['loadtime']->GetSectionLoad('moduleinstallend'), LOGGER_DEBUG);
     }
     return $result;
 }