public function testMergedConfigReader() { $strSimpleConfigFile = <<<TXT <?php \$config["testkey1"] = "testval1"; \$config["testkey2"] = "testval2"; TXT; $strMergingConfigFile = <<<TXT <?php \$config["testkey2"] = "otherval"; TXT; file_put_contents(class_resourceloader::getInstance()->getCorePathForModule("module_system", true) . "/module_system/system/config/test2.php", $strSimpleConfigFile); file_put_contents(_realpath_ . _projectpath_ . "/system/config/test2.php", $strMergingConfigFile); $this->assertFileExists(class_resourceloader::getInstance()->getCorePathForModule("module_system", true) . "/module_system/system/config/test2.php"); $this->assertFileExists(_realpath_ . _projectpath_ . "/system/config/test2.php"); $objConfig = class_config::getInstance("test2.php"); $this->assertEquals("testval1", $objConfig->getConfig("testkey1")); $this->assertEquals("otherval", $objConfig->getConfig("testkey2")); $objFilesystem = new class_filesystem(); $objFilesystem->fileDelete(class_resourceloader::getInstance()->getCorePathForModule("module_system") . "/module_system/system/config/test2.php"); $objFilesystem->fileDelete(_projectpath_ . "/system/config/test2.php"); $this->assertFileNotExists(class_resourceloader::getInstance()->getCorePathForModule("module_system", true) . "/module_system/system/config/test2.php"); $this->assertFileNotExists(_realpath_ . _projectpath_ . "/system/config/test2.php"); }
public function testLogger() { echo "test logger...\n"; $objLogger = class_logger::getInstance("test.log"); $objLogger->setIntLogLevel(class_logger::$levelError); $objLogger->addLogRow("test log row 1", class_logger::$levelInfo); $this->assertEquals($objLogger->getLogFileContent(), ""); $objLogger->setIntLogLevel(class_logger::$levelInfo); $objLogger->addLogRow("test log row 1", class_logger::$levelInfo); $this->assertFileExists(_realpath_ . _projectpath_ . "/log/test.log"); $this->assertTrue(uniStripos($objLogger->getLogFileContent(), "test log row 1") !== false); $objFilesystem = new class_filesystem(); $objFilesystem->fileDelete(_projectpath_ . "/log/test.log"); $this->assertFileNotExists(_realpath_ . _projectpath_ . "/log/test.log"); }
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"); }
public function testZipFileread() { $objFileSystem = new class_filesystem(); echo "\ttesting class_zip file-reading...\n"; $objZip = new class_zip(); echo "\topening " . _realpath_ . "/test.zip\n"; $this->assertTrue($objZip->openArchiveForWriting("/files/cache/test.zip"), __FILE__ . " openArchive"); $this->assertTrue($objZip->addFile(class_resourceloader::getInstance()->getCorePathForModule("module_system") . "/module_system/metadata.xml"), __FILE__ . " addFile"); $this->assertTrue($objZip->closeArchive(), __FILE__ . " closeArchive"); $this->assertFileExists(_realpath_ . "/files/cache/test.zip", __FILE__ . " checkFileExists"); echo "\treading files\n"; $strContent = $objZip->getFileFromArchive("/files/cache/test.zip", class_resourceloader::getInstance()->getCorePathForModule("module_system") . "/module_system/metadata.xml"); $this->assertTrue(uniStrpos($strContent, "xsi:noNamespaceSchemaLocation=\"https://apidocs.kajona.de/xsd/package.xsd\"") !== false); echo "\tremoving testfile\n"; $this->assertTrue($objFileSystem->fileDelete("/files/cache/test.zip"), __FILE__ . " deleteFile"); $this->assertFileNotExists(_realpath_ . "/files/cache/test.zip", __FILE__ . " checkFileNotExists"); $objFileSystem->folderDeleteRecursive("/files/cache/zipextract"); $this->assertFileNotExists(_realpath_ . "/files/cache/zipextract", __FILE__ . " checkFileNotExists"); }
public function testJsonList() { $objFilesystem = new class_filesystem(); $objFilesystem->folderCreate("/files/packageservertest"); $objFilesystem->folderCreate("/files/packageservertest/t"); file_put_contents(_realpath_ . "/files/packageservertest/t/metadata.xml", $this->getStrMetadata()); $objFilesystem->folderCreate("/files/packageservertest/t/system"); file_put_contents(_realpath_ . "/files/packageservertest/t/system/test.txt", $this->getStrMetadata()); $objZip = new class_zip(); $objZip->openArchiveForWriting("/files/packageservertest/autotest.zip"); $objZip->addFile("/files/packageservertest/t/metadata.xml", "/metadata.xml"); $objZip->addFile("/files/packageservertest/t/system/test.txt", "/system/test.txt"); $objZip->closeArchive(); $objFilesystem->folderDeleteRecursive("/files/packageservertest/t"); $objMediamanagerRepo = new class_module_mediamanager_repo(); $objMediamanagerRepo->setStrPath("/files/packageservertest"); $objMediamanagerRepo->setStrTitle("autotest packages"); $objMediamanagerRepo->updateObjectToDb(); class_module_mediamanager_file::syncRecursive($objMediamanagerRepo->getSystemid(), $objMediamanagerRepo->getStrPath()); /** @var $objPortalServer class_module_packageserver_portal */ $objPortalServer = class_module_system_module::getModuleByName("packageserver")->getPortalInstanceOfConcreteModule(); $strJson = $objPortalServer->action("list"); $this->assertNotNull($strJson); $arrData = json_decode($strJson, true); $this->assertTrue(isset($arrData["numberOfTotalItems"])); $this->assertTrue(isset($arrData["items"])); $this->assertTrue(isset($arrData["protocolVersion"])); $this->assertEquals(1, count($arrData["items"])); $arrItem = $arrData["items"][0]; $this->assertTrue(isset($arrItem["systemid"])); $this->assertTrue(isset($arrItem["title"])); $this->assertTrue(isset($arrItem["version"])); $this->assertTrue(isset($arrItem["description"])); $this->assertTrue(isset($arrItem["type"])); $this->assertEquals("Autotest", $arrItem["title"]); $this->assertEquals("3.9.1", $arrItem["version"]); $this->assertEquals("demo", $arrItem["description"]); $this->assertEquals("MODULE", $arrItem["type"]); $objMediamanagerRepo->deleteObjectFromDatabase(); $objFilesystem->fileDelete("/files/packageservertest/autotest.zip"); }
/** * @see interface_admin_systemtask::executeTask() * @return string */ public function executeTask() { if (!class_module_system_module::getModuleByName("system")->rightRight2()) { return $this->getLang("commons_error_permissions"); } $strReturn = ""; //fetch the number of images to be deleted $objFilesystem = new class_filesystem(); $arrFiles = $objFilesystem->getFilelist(_images_cachepath_, array()); $intFilesDeleted = 0; $intTotalFiles = count($arrFiles); foreach ($arrFiles as $strOneFile) { if ($objFilesystem->fileDelete(_images_cachepath_ . "/" . $strOneFile)) { $intFilesDeleted++; } } //build the return string $strReturn .= $this->getLang("systemtask_flushpiccache_done"); $strReturn .= $this->getLang("systemtask_flushpiccache_deleted") . $intFilesDeleted; $strReturn .= $this->getLang("systemtask_flushpiccache_skipped") . ($intTotalFiles - $intFilesDeleted); return $strReturn; }
/** * Tries to compress a given file. * If the passed filename was test.txt, the created file is named * test.txt.gz * * @param string $strFilename * @param bool $bitDeleteSource * * @throws class_exception * @return bool */ public function compressFile($strFilename, $bitDeleteSource = false) { if (strpos($strFilename, _realpath_) === false) { $strFilename = _realpath_ . $strFilename; } //Check if sourcefile exists $strTargetFilename = $strFilename . ".gz"; if (file_exists($strFilename) && is_file($strFilename)) { //try to open target file pointer if ($objTargetPointer = gzopen($strTargetFilename, "wb")) { //try to open sourcefile if ($objSourcePointer = fopen($strFilename, "rb")) { //Loop over filecontent while (!feof($objSourcePointer)) { gzwrite($objTargetPointer, fread($objSourcePointer, 1024 * 512)); } @fclose($objSourcePointer); @gzclose($objTargetPointer); //Delete the sourcefile? if ($bitDeleteSource) { $objFilesystem = new class_filesystem(); $objFilesystem->fileDelete(str_replace(_realpath_, "", $strFilename)); } return true; } else { @gzclose($objTargetPointer); throw new class_exception("can't open sourcefile", class_exception::$level_ERROR); } } else { throw new class_exception("can't open targetfile", class_exception::$level_ERROR); } } else { throw new class_exception("Sourcefile not valid", class_exception::$level_ERROR); } return false; }
/** * @see interface_admin_systemtask::executeTask() * @return string */ public function executeTask() { if (!class_module_system_module::getModuleByName("pages")->rightEdit()) { return $this->getLang("commons_error_permissions"); } $strReturn = ""; $objFilesystem = new class_filesystem(); $strTarget = $this->getParam("pageimport_file"); $strError = $this->getParam("pageimport_error"); $strTopFolderId = $this->getParam("topFolderId"); $bitReplaceExisting = $this->getParam("pageimport_replace") != ""; if ($strError != "suffix") { if ($strError != "upload") { //parse using the kajona xml parser $objXML = new class_xml_parser(); $objXML->loadFile($strTarget); $arrXML = $objXML->xmlToArray(); foreach ($arrXML as $arrOneXml) { foreach ($arrOneXml as $arrNode) { foreach ($arrNode as $strName => $arrSubnode) { if ($strName == "page") { $strReturn .= $this->processSinglePage($arrSubnode[0], $bitReplaceExisting, $strTopFolderId); } } } } $strReturn = $this->getLang("systemtask_pageimport_success") . $strReturn; } else { $strReturn .= $this->getLang("systemtask_pageimport_errorupload"); } } else { $strReturn .= $this->getLang("systemtask_pageimport_errortype"); } $objFilesystem->fileDelete($strTarget); return $strReturn; }
/** * Imports the given dump * * @param string $strFilename * * @return bool */ public function importDb($strFilename) { if (!$this->bitConnected) { $this->dbconnect(); } //gz file? $bitGzip = false; if (substr($strFilename, -3) == ".gz") { $bitGzip = true; //try to decompress $objGzip = new class_gzip(); try { if ($objGzip->decompressFile(_projectpath_ . "/dbdumps/" . $strFilename)) { $strFilename = substr($strFilename, 0, strlen($strFilename) - 3); } else { class_logger::getInstance(class_logger::DBLOG)->addLogRow("Failed to decompress (gzip) the file " . basename($strFilename) . "", class_logger::$levelWarning); return false; } } catch (class_exception $objExc) { $objExc->processException(); return false; } } $bitImport = $this->objDbDriver->dbImport(_projectpath_ . "/dbdumps/" . $strFilename); //Delete source unzipped file? if ($bitGzip) { $objFilesystem = new class_filesystem(); $objFilesystem->fileDelete(_projectpath_ . "/dbdumps/" . $strFilename); } if ($bitImport) { class_logger::getInstance(class_logger::DBLOG)->addLogRow("DB-DUMP " . $strFilename . " was restored", class_logger::$levelWarning); } else { class_logger::getInstance(class_logger::DBLOG)->addLogRow("Error restoring DB-DUMP " . $strFilename, class_logger::$levelError); } return $bitImport; }
/** * Flushes the cache-files. * Use this method if you added new modules / classes. * @return void */ public static function flushCache() { $objFilesystem = new class_filesystem(); $objFilesystem->fileDelete(self::$strAnnotationsCacheFile); }
/** * @permissions edit * @return string */ protected function actionUploadPackage() { $this->setArrModuleEntry("template", "/folderview.tpl"); $objManager = new class_module_packagemanager_manager(); $arrContentProvider = $objManager->getContentproviders(); $strProvider = $this->getParam("provider"); $objProvider = null; foreach ($arrContentProvider as $objOneProvider) { if (get_class($objOneProvider) == $strProvider) { $objProvider = $objOneProvider; } } if ($objProvider == null) { return $this->getLang("commons_error_permissions"); } $strFile = $objProvider->processPackageUpload(); if ($strFile == null) { return $this->renderError("provider_error_transfer", "packagemanager"); } if (!$objManager->validatePackage($strFile)) { $objFilesystem = new class_filesystem(); $objFilesystem->fileDelete($strFile); return $this->getLang("provider_error_package", "packagemanager"); } $this->adminReload(class_link::getLinkAdminHref($this->getArrModule("modul"), "processPackage", "&package=" . $strFile)); return ""; }
/** * Flushes the cache-files. * Use this method if you added new modules / classes. * The classes are reinitialized automatically. * * @return void */ public function flushCache() { $objFilesystem = new class_filesystem(); $objFilesystem->fileDelete($this->strModulesCacheFile); $objFilesystem->fileDelete($this->strClassesCacheFile); $this->arrFiles = array(); $this->arrModules = array(); $this->scanModules(); $this->indexAvailableCodefiles(); }
private function update_45_46() { $strReturn = "Updating 4.5 to 4.6...\n"; $strReturn .= "Removing stats-collector scriptlet, now handled by an event-listener\n"; if (is_file(_realpath_ . "/core/module_stats/system/scriptlets/class_scriptlet_statscollector.php")) { $objFilesystem = new class_filesystem(); if (!$objFilesystem->fileDelete("/core/module_stats/system/scriptlets/class_scriptlet_statscollector.php")) { $strReturn .= "Error deleting file /core/module_stats/system/scriptlets/class_scriptlet_statscollector.php, aborting update!\n"; return $strReturn; } } $strReturn .= "Deleting old browscap.ini file...\n"; $objFS = new class_filesystem(); $objFS->fileDelete("/core/module_stats/system/php_browscap.ini"); $strReturn .= "Updating module-versions...\n"; $this->updateModuleVersion("stats", "4.6"); return $strReturn; }
private function update_441_45() { $strReturn = "Updating 4.4[.1] to 4.5...\n"; // Install Index if (!$this->bitIndexTablesUpToDate) { $strReturn .= "Updating index tables...\n"; $strQuery = "ALTER TABLE " . $this->objDB->encloseTableName(_dbprefix_ . "search_ix_document") . "\n ADD " . $this->objDB->encloseColumnName("search_ix_content_lang") . " " . $this->objDB->getDatatype("char20") . " NULL"; if (!$this->objDB->_pQuery($strQuery, array())) { $strReturn .= "An error occurred! ...\n"; } $strQuery = "ALTER TABLE " . $this->objDB->encloseTableName(_dbprefix_ . "search_ix_document") . "\n ADD " . $this->objDB->encloseColumnName("search_ix_portal_object") . " " . $this->objDB->getDatatype("int") . " NULL"; if (!$this->objDB->_pQuery($strQuery, array())) { $strReturn .= "An error occurred! ...\n"; } $this->objDB->_pQuery("CREATE INDEX ix_search_ix_content_lang ON " . $this->objDB->encloseTableName(_dbprefix_ . "search_ix_document") . " ( " . $this->objDB->encloseColumnName("search_ix_content_lang") . " ) ", array()); $this->objDB->_pQuery("CREATE INDEX ix_search_ix_portal_object ON " . $this->objDB->encloseTableName(_dbprefix_ . "search_ix_document") . " ( " . $this->objDB->encloseColumnName("search_ix_portal_object") . " ) ", array()); } $strReturn .= "Removing old searchplugins...\n"; $objFilesystem = new class_filesystem(); foreach (class_resourceloader::getInstance()->getFolderContent("/admin/searchplugins/") as $strPath => $strFilename) { $strReturn .= "Deleting " . $strPath . "\n"; $objFilesystem->fileDelete($strPath); } foreach (class_resourceloader::getInstance()->getFolderContent("/portal/searchplugins/") as $strPath => $strFilename) { $strReturn .= "Deleting " . $strPath . "\n"; $objFilesystem->fileDelete($strPath); } $strReturn .= "Updating module-versions...\n"; $this->updateModuleVersion("search", "4.5"); $this->updateElementVersion("search", "4.5"); $strReturn .= "Updating index...\n"; if (@ini_get("max_execution_time") < 3600 && @ini_get("max_execution_time") > 0) { @ini_set("max_execution_time", "3600"); } $this->bitIndexRebuild = true; $strReturn .= "Please make sure to update your searchindex manually as soon as all other packages have been updated.\n"; $strReturn .= "An index-rebuild can be started using module system, action systemtasks, task 'Rebuild search index'."; return $strReturn; }
private function update_47_475() { $strReturn = "Updating 4.7 to 4.7.5...\n"; $strReturn .= "Removing messagesummary login-listeners...\n"; $objFilesystem = new class_filesystem(); if (is_file(_realpath_ . "/core/module_workflows/system/class_module_messagesummary_firstloginlistener.php")) { $objFilesystem->fileDelete("/core/module_workflows/system/class_module_messagesummary_firstloginlistener.php"); } if (is_file(_realpath_ . "/project/system/class_module_messagesummary_firstloginlistener.php")) { $objFilesystem->fileDelete("/project/system/class_module_messagesummary_firstloginlistener.php"); } $strReturn .= "Updating module-versions...\n"; $this->updateModuleVersion($this->objMetadata->getStrTitle(), "4.7.5"); return $strReturn; }
/** * Deletes all cached resource-information, * so the .cache-files. * @return void */ public function flushCache() { $objFilesystem = new class_filesystem(); $objFilesystem->fileDelete($this->strTemplatesCacheFile); $objFilesystem->fileDelete($this->strFoldercontentCacheFile); $objFilesystem->fileDelete($this->strFoldercontentLangFile); $this->arrModules = class_classloader::getInstance()->getArrModules(); $this->arrFoldercontent = array(); $this->arrTemplates = array(); $this->arrLangfiles = array(); }
public function deleteObjectFromDatabase() { //delete the current file if ($this->getParam("deleteMediamanagerRepo") != true) { $objFilesystem = new class_filesystem(); if ($this->getIntType() == self::$INT_TYPE_FILE) { $objFilesystem->fileDelete($this->getStrFilename()); } else { $objFilesystem->folderDelete($this->getStrFilename()); } } return parent::deleteObjectFromDatabase(); }
private function update_43_431() { $strReturn = "Updating 4.3 to 4.3.1...\n"; $strReturn .= "This update removes the flot chart module and replaces it with the jqplot chart module...\n\n"; //1. install module jqplot $strReturn .= "Installing module jqplot if not exist...\n"; $objManager = new class_module_packagemanager_manager(); $objExistingJqPlotPackage = $objManager->getPackage("jqplot"); //if jqplot is not installed, install it if ($objExistingJqPlotPackage === null) { $objContentProvider = new class_module_packagemanager_contentprovider_kajona(); $arrPackageMetaData = $objContentProvider->searchPackage("jqplot"); //if a package was found if ($arrPackageMetaData !== null && count($arrPackageMetaData) == 1) { //upload the package to projects/temp class_carrier::getInstance()->setParam("systemid", $arrPackageMetaData[0]["systemid"]); $strFile = $objContentProvider->processPackageUpload(); if ($objManager->validatePackage($strFile)) { if (uniSubstr($strFile, -4) == ".zip") { //now extract the zip file and...... $objHandler = $objManager->extractPackage($strFile); $objFilesystem = new class_filesystem(); $objFilesystem->fileDelete($strFile); //move the created folder to /core $objHandler->move2Filesystem(); } } else { $strReturn .= "Package file is not valid...\n"; $strReturn .= "Update to version 4.3.1 cancelled...\n"; return $strReturn; } } else { $strReturn = "Module jqplot was not found via the packagemanager...\n"; $strReturn .= "Update to version 4.3.1 cancelled...\n"; return $strReturn; } } //2. uninstall module flot $strReturn .= "Removing module flotchart if exists...\n"; $objFlotPackage = $objManager->getPackage("flotchart"); if ($objFlotPackage !== null) { //uninstall flot $class_filesystem = new class_filesystem(); $class_filesystem->folderDeleteRecursive($objFlotPackage->getStrPath()); } //3. set jqplot as standard chart library $strReturn .= "Set jqplot as standard chart library if flot was selected standard chart library...\n"; $objSetting = class_module_system_setting::getConfigByName("_system_graph_type_"); if ($objSetting->getStrValue() == "flot") { $objSetting->setStrValue("jqplot"); $objSetting->updateObjectToDb(); } //4. update version to 4.3.1 $strReturn .= "Updating module-versions...\n"; $this->updateModuleVersion("", "4.3.1"); //5. reload classloader etc. class_resourceloader::getInstance()->flushCache(); class_classloader::getInstance()->flushCache(); class_reflection::flushCache(); return $strReturn; }