/**
  * Generic implementation, triggers the update or the install method, depending on the parts already installed.
  * @return string
  */
 public function installOrUpdate()
 {
     $strReturn = "";
     $objModule = null;
     if ($this->objMetadata->getStrType() == class_module_packagemanager_manager::STR_TYPE_ELEMENT) {
         if (class_module_system_module::getModuleByName("pages") !== null && is_dir(class_resourceloader::getInstance()->getCorePathForModule("module_pages", true))) {
             $objModule = class_module_pages_element::getElement(uniStrReplace("element_", "", $this->objMetadata->getStrTitle()));
         }
     } else {
         $objModule = class_module_system_module::getModuleByName($this->objMetadata->getStrTitle());
     }
     if ($objModule === null) {
         class_logger::getInstance("triggering installation of " . $this->objMetadata->getStrTitle(), class_logger::$levelInfo);
         $strReturn .= $this->install();
     } else {
         $strVersionInstalled = $objModule->getStrVersion();
         $strVersionAvailable = $this->objMetadata->getStrVersion();
         if (version_compare($strVersionAvailable, $strVersionInstalled, ">")) {
             class_logger::getInstance("triggering update of " . $this->objMetadata->getStrTitle(), class_logger::$levelInfo);
             $strReturn .= $this->update();
         }
     }
     class_carrier::getInstance()->flushCache(class_carrier::INT_CACHE_TYPE_DBTABLES);
     return $strReturn;
 }
 /**
  * In nearly all cases, the additional info is rendered left to the action-icons.
  *
  * @return string
  */
 public function getStrAdditionalInfo()
 {
     $strReturn = "";
     if ($this->objMetadata == null) {
         return "";
     }
     if ($this->objMetadata->getStrVersion() != "") {
         $strReturn .= $this->getLang("pack_version") . " " . $this->objMetadata->getStrVersion();
     }
     if ($this->objMetadata->getStrAuthor() != "") {
         $strReturn .= " " . $this->getLang("pack_author") . " " . $this->objMetadata->getStrAuthor();
     }
     return $strReturn;
 }
 /**
  * Validates, whether the current package is installable or not.
  * In nearly all cases
  *
  * @return bool
  */
 public function isInstallable()
 {
     if (!$this->getObjMetadata()->getBitProvidesInstaller()) {
         return false;
     }
     //check if required modules are given in matching versions
     $arrRequiredModules = $this->objMetadata->getArrRequiredModules();
     foreach ($arrRequiredModules as $strOneModule => $strMinVersion) {
         if (trim($strOneModule) != "") {
             $objModule = class_module_system_module::getModuleByName(trim($strOneModule));
             if ($objModule === null) {
                 $arrModules = class_resourceloader::getInstance()->getArrModules();
                 $objMetadata = null;
                 foreach ($arrModules as $strPath => $strOneFolder) {
                     if (uniStrpos($strOneFolder, $strOneModule) !== false) {
                         $objMetadata = new class_module_packagemanager_metadata();
                         $objMetadata->autoInit("/" . $strPath);
                         //but: if the package provides an installer and was not resolved by the previous calls,
                         //we shouldn't include it here
                         if ($objMetadata->getBitProvidesInstaller()) {
                             $objMetadata = null;
                         }
                     }
                 }
                 //no package found
                 if ($objMetadata === null) {
                     return false;
                 }
                 //package found, but wrong version
                 if (version_compare($strMinVersion, $objMetadata->getStrVersion(), ">")) {
                     return false;
                 }
             } else {
                 if (version_compare($strMinVersion, $objModule->getStrVersion(), ">")) {
                     return false;
                 }
             }
         }
     }
     //compare versions of installed elements
     $objModule = class_module_system_module::getModuleByName($this->getObjMetadata()->getStrTitle());
     if ($objModule !== null) {
         if (version_compare($this->objMetadata->getStrVersion(), $objModule->getStrVersion(), ">")) {
             return true;
         } else {
             return false;
         }
     } else {
         return true;
     }
 }
 public function testExtractAndMove()
 {
     $objFilesystem = new class_filesystem();
     $objFilesystem->folderCreate(_projectpath_ . "/temp/moduletest");
     file_put_contents(_realpath_ . _projectpath_ . "/temp/moduletest/metadata.xml", $this->getStrMetadata());
     $objFilesystem->folderCreate(_projectpath_ . "/temp/moduletest/system");
     file_put_contents(_realpath_ . _projectpath_ . "/temp/moduletest/system/test.txt", $this->getStrMetadata());
     $objZip = new class_zip();
     $objZip->openArchiveForWriting(_projectpath_ . "/temp/autotest.zip");
     $objZip->addFile(_projectpath_ . "/temp/moduletest/metadata.xml", "/metadata.xml");
     $objZip->addFile(_projectpath_ . "/temp/moduletest/system/test.txt", "/system/test.txt");
     $objZip->closeArchive();
     $objFilesystem->folderDeleteRecursive(_projectpath_ . "/temp/moduletest/");
     $objManager = new class_module_packagemanager_manager();
     $objPackageManager = $objManager->getPackageManagerForPath(_projectpath_ . "/temp/autotest.zip");
     $this->assertEquals(get_class($objPackageManager), "class_module_packagemanager_packagemanager_module");
     $objPackageManager = $objManager->extractPackage(_projectpath_ . "/temp/autotest.zip");
     $this->assertEquals(get_class($objPackageManager), "class_module_packagemanager_packagemanager_module");
     $objPackageManager->move2Filesystem();
     $this->assertFileExists(_realpath_ . "/core/module_autotest/metadata.xml");
     $this->assertFileExists(_realpath_ . "/core/module_autotest/system/test.txt");
     $objMetadata = new class_module_packagemanager_metadata();
     $objMetadata->autoInit("/core/module_autotest/");
     $this->assertEquals("Autotest", $objMetadata->getStrTitle());
     $this->assertEquals("", $objMetadata->getStrDescription());
     $this->assertEquals("3.9.1", $objMetadata->getStrVersion());
     $this->assertEquals("Kajona Team", $objMetadata->getStrAuthor());
     $this->assertEquals("module_autotest", $objMetadata->getStrTarget());
     $this->assertEquals(class_module_packagemanager_manager::STR_TYPE_MODULE, $objMetadata->getStrType());
     $this->assertEquals(false, $objMetadata->getBitProvidesInstaller());
     $arrRequired = $objMetadata->getArrRequiredModules();
     $arrModules = array_keys($arrRequired);
     $arrVersion = array_values($arrRequired);
     $this->assertEquals("system", $arrModules[0]);
     $this->assertEquals("3.4.1", $arrVersion[0]);
     $this->assertEquals("pages", $arrModules[1]);
     $this->assertEquals("3.4.2", $arrVersion[1]);
     $arrImages = $objMetadata->getArrScreenshots();
     $this->assertEquals(1, count($arrImages));
     $this->assertEquals("/test.jpg", $arrImages[0]);
     $objFilesystem->folderDeleteRecursive("/core/module_autotest");
     $objFilesystem->fileDelete(_projectpath_ . "/temp/autotest.zip");
 }
 /**
  * Gets the version of the package currently installed.
  * If not installed, null should be returned instead.
  *
  * @return string|null
  */
 public function getVersionInstalled()
 {
     $strTarget = $this->getStrTargetPath();
     if (is_dir(_realpath_ . $strTarget)) {
         $objManager = new class_module_packagemanager_metadata();
         $objManager->autoInit($strTarget);
         return $objManager->getStrVersion();
     }
     return null;
 }