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 install() { $strReturn = ""; $strReturn .= "Installing table packageserver_log...\n"; $arrFields = array(); $arrFields["log_id"] = array("char20", false); $arrFields["log_query"] = array("text", true); $arrFields["log_ip"] = array("char254", true); $arrFields["log_hostname"] = array("char254", true); $arrFields["log_date"] = array("long", true); if (!$this->objDB->createTable("packageserver_log", $arrFields, array("log_id"), array("log_date"), false)) { $strReturn .= "An error occurred! ...\n"; } //register the module $this->registerModule("packageserver", _packageserver_module_id_, "class_module_packageserver_portal.php", "class_module_packageserver_admin.php", $this->objMetadata->getStrVersion(), true); $strReturn .= "creating package-upload-repository...\n"; $objFilesytem = new class_filesystem(); $objFilesytem->folderCreate("/files/packages"); $objRepo = new class_module_mediamanager_repo(); $objRepo->setStrPath("/files/packages"); $objRepo->setStrViewFilter(".zip"); $objRepo->setStrUploadFilter(".zip"); $objRepo->setStrTitle("Packageserver packages"); $objRepo->updateObjectToDb(); class_carrier::getInstance()->getObjRights()->addGroupToRight(class_module_system_setting::getConfigValue("_guests_group_id_"), $objRepo->getSystemid(), class_rights::$STR_RIGHT_RIGHT2); $strReturn .= "Registering system-constants...\n"; $this->registerConstant("_packageserver_repo_id_", "", class_module_system_setting::$int_TYPE_STRING, _packageserver_module_id_); $strReturn .= "Setting aspect assignments...\n"; if (class_module_system_aspect::getAspectByName("content") != null) { $objModule = class_module_system_module::getModuleByName($this->objMetadata->getStrTitle()); $objModule->setStrAspect(class_module_system_aspect::getAspectByName("content")->getSystemid()); $objModule->updateObjectToDb(); } return $strReturn; }
/** * Invokes the installer, if given. * The installer itself is capable of detecting whether an update or a plain installation is required. * * @throws class_exception * @return string */ public function installOrUpdate() { $strReturn = ""; if (uniStrpos($this->getObjMetadata()->getStrPath(), "core") === false) { throw new class_exception("Current module not located at /core*.", class_exception::$level_ERROR); } if (!$this->isInstallable()) { throw new class_exception("Current module isn't installable, not all requirements are given", class_exception::$level_ERROR); } //search for an existing installer $objFilesystem = new class_filesystem(); $arrInstaller = $objFilesystem->getFilelist($this->objMetadata->getStrPath() . "/installer/", array(".php")); if ($arrInstaller === false) { $strReturn .= "Updating default template pack...\n"; $this->updateDefaultTemplate(); class_cache::flushCache(); return $strReturn; } //proceed with elements foreach ($arrInstaller as $strOneInstaller) { //skip samplecontent files if (uniStrpos($strOneInstaller, "element") !== false) { class_logger::getInstance(class_logger::PACKAGEMANAGEMENT)->addLogRow("triggering updateOrInstall() on installer " . $strOneInstaller . ", all requirements given", class_logger::$levelInfo); //trigger update or install $strName = uniSubstr($strOneInstaller, 0, -4); /** @var $objInstaller interface_installer */ $objInstaller = new $strName(); $strReturn .= $objInstaller->installOrUpdate(); } } $strReturn .= "Updating default template pack...\n"; $this->updateDefaultTemplate(); return $strReturn; }
public function resetSQLite() { $strProjectSQLitePath = "project/dbdumps/"; echo "\n\n\nLooking for Selenium SQLite file in " . $strProjectSQLitePath; if (file_exists(_realpath_ . "/" . $strProjectSQLitePath . "seleniumtest.db3")) { echo "\n\nseleniumtest.db3 found. I will rename it to seleniumtest.selbck-" . $this->strTimestamp; $objFilesystem = new class_filesystem(); $objFilesystem->fileRename($strProjectSQLitePath . "seleniumtest.db3", $strProjectSQLitePath . "seleniumtest.selbck-" . $this->strTimestamp, true); } else { echo "\n\nNo seleniumtest.db3 in project folder found."; } }
public function deleteFolder(class_filesystem $objFilesystem, $strDirName) { if (is_dir(_realpath_ . $strDirName)) { echo "\n Found existing folder " . $strDirName . ", delete it..."; $boolDeleteAction = @$objFilesystem->folderDeleteRecursive($strDirName); if ($boolDeleteAction === false) { die("\n\n ERROR: Folder " . $strDirName . " can not be deleted! Permission denied!"); } } else { echo "\n Ok, " . $strDirName . " does not already exist."; } }
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"); }
/** * Renders the field itself. * In most cases, based on the current toolkit. * * @return string */ public function renderField() { $objToolkit = class_carrier::getInstance()->getObjToolkit("admin"); $strReturn = ""; if ($this->getStrHint() != null) { $strReturn .= $objToolkit->formTextRow($this->getStrHint()); } $arrFiles = array(); if ($this->getSourceDir() !== null) { $objFilesystem = new class_filesystem(); $arrPlainFiles = $objFilesystem->getFilelist($this->getSourceDir()); $arrFiles = array_combine($arrPlainFiles, $arrPlainFiles); } $strReturn .= $objToolkit->formInputDropdown($this->getStrEntryName(), $arrFiles, $this->getStrLabel(), $this->getStrValue(), "", !$this->getBitReadonly()); return $strReturn; }
/** * Traverses the folder and adds the folder recursively. * * @param string $strFolder * * @return bool */ public function addFolder($strFolder) { $bitReturn = true; if (is_dir(_realpath_ . $strFolder)) { $objFilesystem = new class_filesystem(); $arrFiles = $objFilesystem->getCompleteList($strFolder, array(), array(), array(".", "..")); foreach ($arrFiles["files"] as $arrOneFile) { $bitReturn = $bitReturn && $this->addFile($arrOneFile["filepath"]); } foreach ($arrFiles["folders"] as $strOneFolder) { $bitReturn = $bitReturn && $this->addFolder($strFolder . "/" . $strOneFolder); } return $bitReturn; } return false; }
public function testFileSync() { echo "test mediamanager...\n"; if (class_module_system_module::getModuleByName("samplecontent") == null || !is_file(_realpath_ . "/files/images/samples/IMG_3000.JPG")) { return; } $objFilesystem = new class_filesystem(); $objFilesystem->folderCreate(_filespath_ . "/images/autotest"); $objFilesystem->fileCopy(_filespath_ . "/images/samples/IMG_3000.JPG", _filespath_ . "/images/autotest/IMG_3000.jpg"); $objFilesystem->fileCopy(_filespath_ . "/images/samples/IMG_3000.JPG", _filespath_ . "/images/autotest/IMG_3000.png"); $objFilesystem->fileCopy(_filespath_ . "/images/samples/IMG_3000.JPG", _filespath_ . "/images/autotest/PA021805.JPG"); $objFilesystem->fileCopy(_filespath_ . "/images/samples/IMG_3000.JPG", _filespath_ . "/images/autotest/test.txt"); $objRepo = new class_module_mediamanager_repo(); $objRepo->setStrPath(_filespath_ . "/images/autotest"); $objRepo->setStrTitle("autotest repo"); $objRepo->setStrViewFilter(".jpg,.png"); $objRepo->updateObjectToDb(); $objRepo->syncRepo(); $arrFiles = class_module_mediamanager_file::loadFilesDB($objRepo->getSystemid()); $this->assertEquals(3, count($arrFiles)); foreach ($arrFiles as $objOneFile) { $objOneFile->deleteObjectFromDatabase(); } $objRepo->deleteObjectFromDatabase(); $arrFiles = $objFilesystem->getFilelist(_filespath_ . "/images/autotest"); $this->assertEquals(1, count($arrFiles)); $this->assertEquals("test.txt", array_values($arrFiles)[0]); }
/** * This method is called, when the widget should generate it's content. * Return the complete content using the methods provided by the base class. * Do NOT use the toolkit right here! * @return string */ public function getWidgetOutput() { $strReturn = ""; if (!class_module_system_module::getModuleByName("system")->rightRight3() || !class_carrier::getInstance()->getObjSession()->isSuperAdmin()) { return $this->getLang("commons_error_permissions"); } $objFilesystem = new class_filesystem(); $arrFiles = $objFilesystem->getFilelist(_projectpath_ . "/log", array(".log")); foreach ($arrFiles as $strName) { $objFilesystem->openFilePointer(_projectpath_ . "/log/" . $strName, "r"); $strLogContent = $objFilesystem->readLastLinesFromFile($this->getFieldValue("nrofrows")); $objFilesystem->closeFilePointer(); $strLogContent = str_replace(array("INFO", "ERROR"), array("INFO ", "ERROR "), $strLogContent); $arrLogEntries = explode("\r", $strLogContent); $strReturn .= $this->objToolkit->getPreformatted($arrLogEntries); } return $strReturn; }
/** * @param $strPath * @return void */ private function recursiveImageProcessing($strPath) { $objFilesystem = new class_filesystem(); $arrFilesFolders = $objFilesystem->getCompleteList($strPath, array(".jpg", ".jpeg", ".png", ".gif"), array(), array(".", "..", ".svn")); $this->intFilesTotal += $arrFilesFolders["nrFiles"]; foreach ($arrFilesFolders["folders"] as $strOneFolder) { $this->recursiveImageProcessing($strPath . "/" . $strOneFolder); } foreach ($arrFilesFolders["files"] as $arrOneFile) { $strImagePath = $strPath . "/" . $arrOneFile["filename"]; $objImage = new class_image2(); $objImage->setUseCache(false); $objImage->load($strImagePath); $objImage->addOperation(new class_image_scale($this->intMaxWidth, $this->intMaxHeight)); if ($objImage->save($strImagePath)) { $this->intFilesProcessed++; } } }
function walkFolderRecursive($strStartFolder) { $objFilesystem = new class_filesystem(); $arrFilesAndFolders = $objFilesystem->getCompleteList($strStartFolder, array(".php"), array(), array(".", "..", ".svn")); foreach ($arrFilesAndFolders["files"] as $arrOneFile) { $strFilename = $arrOneFile["filename"]; //include the filecontent $strContent = file_get_contents($strStartFolder . "/" . $strFilename); if (uniSubstr($strContent, 0, 5) != "<?php") { echo "Whitespace at the beginning of file >> " . $strStartFolder . "/" . $strFilename . " is:>" . uniSubstr($strContent, 0, 1) . "< << \n"; } if (uniSubstr($strContent, -2) != "?>") { echo "Whitespace at the end of file >> " . $strStartFolder . "/" . $strFilename . " << \n"; } } foreach ($arrFilesAndFolders["folders"] as $strOneFolder) { walkFolderRecursive($strStartFolder . "/" . $strOneFolder); } }
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"); }
/** * Copies the extracted(!) package from the temp-folder * to the target-folder. * In most cases, this is either located at /core or at /templates. * The original should be deleted afterwards. * * @throws class_exception * @return void */ public function move2Filesystem() { $strSource = $this->objMetadata->getStrPath(); if (!is_dir(_realpath_ . $strSource)) { throw new class_exception("current package " . $strSource . " is not a folder.", class_exception::$level_ERROR); } $objFilesystem = new class_filesystem(); $objFilesystem->chmod($this->getStrTargetPath(), 0777); class_logger::getInstance(class_logger::PACKAGEMANAGEMENT)->addLogRow("moving " . $strSource . " to " . $this->getStrTargetPath(), class_logger::$levelInfo); $objFilesystem->folderCopyRecursive($strSource, $this->getStrTargetPath(), true); $this->objMetadata->setStrPath($this->getStrTargetPath()); $objFilesystem->chmod($this->getStrTargetPath()); $objFilesystem->folderDeleteRecursive($strSource); //shift the cache buster $objSetting = class_module_system_setting::getConfigByName("_system_browser_cachebuster_"); if ($objSetting != null) { $objSetting->setStrValue((int) $objSetting->getStrValue() + 1); $objSetting->updateObjectToDb(); } }
/** * Loads the feed and displays it * * @return string the prepared html-output */ public function loadData() { $strReturn = ""; //Load all files in the folder $objFilesystem = new class_filesystem(); $arrFiles = $objFilesystem->getFilelist($this->arrElementData["char2"]); $strWrapperTemplateID = $this->objTemplate->readTemplate("/element_directorybrowser/" . $this->arrElementData["char1"], "directorybrowser_wrapper"); $strEntryTemplateID = $this->objTemplate->readTemplate("/element_directorybrowser/" . $this->arrElementData["char1"], "directorybrowser_entry"); $strContent = ""; foreach ($arrFiles as $strOneFile) { $arrDetails = $objFilesystem->getFileDetails($this->arrElementData["char2"] . "/" . $strOneFile); $arrTemplate = array(); $arrTemplate["file_name"] = $arrDetails["filename"]; $arrTemplate["file_href"] = _webpath_ . $this->arrElementData["char2"] . "/" . $strOneFile; $arrTemplate["file_date"] = timeToString($arrDetails["filechange"]); $arrTemplate["file_size"] = bytesToString($arrDetails["filesize"]); $strContent .= $this->fillTemplate($arrTemplate, $strEntryTemplateID); } $strReturn .= $this->fillTemplate(array("files" => $strContent), $strWrapperTemplateID); return $strReturn; }
/** * The real "download" or "upload" should be handled right here. * All packages have to be downloaded to /project/temp in order to be processed afterwards. * * @return string the filename of the package downloaded */ public function processPackageUpload() { //fetch the upload, validate a few settings and copy the package to /project/temp $arrSource = class_carrier::getInstance()->getParam("provider_local_file"); $strTarget = "/project/temp/" . generateSystemid() . ".zip"; $objFilesystem = new class_filesystem(); //Check file for correct filters $strSuffix = uniStrtolower(uniSubstr($arrSource["name"], uniStrrpos($arrSource["name"], "."))); if (in_array($strSuffix, array(".zip"))) { if ($objFilesystem->copyUpload($strTarget, $arrSource["tmp_name"])) { class_logger::getInstance(class_logger::PACKAGEMANAGEMENT)->addLogRow("uploaded package " . $arrSource["name"] . " to " . $strTarget, class_logger::$levelInfo); class_resourceloader::getInstance()->flushCache(); class_classloader::getInstance()->flushCache(); class_reflection::flushCache(); return $strTarget; } } class_logger::getInstance(class_logger::PACKAGEMANAGEMENT)->addLogRow("error in uploaded package " . $arrSource["name"] . " either wrong format or not writeable target folder", class_logger::$levelInfo); @unlink($arrSource["tmp_name"]); return null; }
/** * @see interface_admin_systemtask::getAdminForm() * @return string */ public function getAdminForm() { $strReturn = ""; //show dropdown to select db-dump $objFilesystem = new class_filesystem(); $arrFiles = $objFilesystem->getFilelist(_projectpath_ . "/dbdumps/", array(".sql", ".gz")); $arrOptions = array(); foreach ($arrFiles as $strOneFile) { $arrDetails = $objFilesystem->getFileDetails(_projectpath_ . "/dbdumps/" . $strOneFile); $strTimestamp = ""; if (uniStrpos($strOneFile, "_") !== false) { $strTimestamp = uniSubstr($strOneFile, uniStrrpos($strOneFile, "_") + 1, uniStrpos($strOneFile, ".") - uniStrrpos($strOneFile, "_")); } if (uniStrlen($strTimestamp) > 9 && is_numeric($strTimestamp)) { $arrOptions[$strOneFile] = $strOneFile . " (" . bytesToString($arrDetails["filesize"]) . ")" . "<br />" . $this->getLang("systemtask_dbimport_datefilename") . " " . timeToString($strTimestamp) . "<br />" . $this->getLang("systemtask_dbimport_datefileinfo") . " " . timeToString($arrDetails['filechange']); } else { $arrOptions[$strOneFile] = $strOneFile . " (" . bytesToString($arrDetails["filesize"]) . ")" . "<br />" . $this->getLang("systemtask_dbimport_datefileinfo") . " " . timeToString($arrDetails['filechange']); } } $strReturn .= $this->objToolkit->formInputRadiogroup("dbImportFile", $arrOptions, $this->getLang("systemtask_dbimport_file")); return $strReturn; }
/** * @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; }
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 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"); }
/** * Tries to save the passed file. * Therefore, the following post-params should be given: * action = fileUpload * folder = the folder to store the file within * systemid = the filemanagers' repo-id * inputElement = name of the inputElement * * @return string * @permissions right1 */ protected function actionFileupload() { $strReturn = ""; /** @var class_module_mediamanager_repo|class_module_mediamanager_file $objFile */ $objFile = class_objectfactory::getInstance()->getObject($this->getSystemid()); /** * @var class_module_mediamanager_repo */ $objRepo = null; if ($objFile instanceof class_module_mediamanager_file) { $strFolder = $objFile->getStrFilename(); if (!$objFile->rightEdit() || $objFile->getIntType() != class_module_mediamanager_file::$INT_TYPE_FOLDER) { class_response_object::getInstance()->setStrStatusCode(class_http_statuscodes::SC_UNAUTHORIZED); $strReturn .= "<message><error>" . xmlSafeString($this->getLang("commons_error_permissions")) . "</error></message>"; return $strReturn; } $objRepo = class_objectfactory::getInstance()->getObject($objFile->getPrevId()); while (!$objRepo instanceof class_module_mediamanager_repo) { $objRepo = class_objectfactory::getInstance()->getObject($objRepo->getPrevId()); } } elseif ($objFile instanceof class_module_mediamanager_repo) { $objRepo = $objFile; $strFolder = $objFile->getStrPath(); if (!$objFile->rightEdit()) { class_response_object::getInstance()->setStrStatusCode(class_http_statuscodes::SC_UNAUTHORIZED); $strReturn .= "<message><error>" . xmlSafeString($this->getLang("commons_error_permissions")) . "</error></message>"; return $strReturn; } } else { class_response_object::getInstance()->setStrStatusCode(class_http_statuscodes::SC_UNAUTHORIZED); $strReturn .= "<message><error>" . xmlSafeString($this->getLang("commons_error_permissions")) . "</error></message>"; return $strReturn; } //Handle the fileupload $arrSource = $this->getParam($this->getParam("inputElement")); $bitJsonResponse = $this->getParam("jsonResponse") != ""; $bitPostData = false; if (is_array($arrSource)) { $strFilename = $arrSource["name"]; } else { $bitPostData = getPostRawData() != ""; $strFilename = $arrSource; } $strTarget = $strFolder . "/" . createFilename($strFilename); $objFilesystem = new class_filesystem(); if (!file_exists(_realpath_ . "/" . $strFolder)) { $objFilesystem->folderCreate($strFolder, true); } if ($objFilesystem->isWritable($strFolder)) { //Check file for correct filters $arrAllowed = explode(",", $objRepo->getStrUploadFilter()); $strSuffix = uniStrtolower(uniSubstr($strFilename, uniStrrpos($strFilename, "."))); if ($objRepo->getStrUploadFilter() == "" || in_array($strSuffix, $arrAllowed)) { if ($bitPostData) { $objFilesystem = new class_filesystem(); $objFilesystem->openFilePointer($strTarget); $bitCopySuccess = $objFilesystem->writeToFile(getPostRawData()); $objFilesystem->closeFilePointer(); } else { $bitCopySuccess = $objFilesystem->copyUpload($strTarget, $arrSource["tmp_name"]); } if ($bitCopySuccess) { if ($bitJsonResponse) { $strReturn = json_encode(array('success' => true)); } else { $strReturn .= "<message>" . $this->getLang("xmlupload_success") . "</message>"; } class_logger::getInstance()->addLogRow("uploaded file " . $strTarget, class_logger::$levelInfo); $objRepo->syncRepo(); } else { if ($bitJsonResponse) { $strReturn .= json_encode(array('error' => $this->getLang("xmlupload_error_copyUpload"))); } else { $strReturn .= "<message><error>" . $this->getLang("xmlupload_error_copyUpload") . "</error></message>"; } } } else { class_response_object::getInstance()->setStrStatusCode(class_http_statuscodes::SC_BADREQUEST); if ($bitJsonResponse) { $strReturn .= json_encode(array('error' => $this->getLang("xmlupload_error_filter"))); } else { $strReturn .= "<message><error>" . $this->getLang("xmlupload_error_filter") . "</error></message>"; } } } else { class_response_object::getInstance()->setStrStatusCode(class_http_statuscodes::SC_INTERNAL_SERVER_ERROR); if ($bitJsonResponse) { $strReturn .= json_encode(array('error' => $this->getLang("xmlupload_error_notWritable"))); } else { $strReturn .= "<message><error>" . xmlSafeString($this->getLang("xmlupload_error_notWritable")) . "</error></message>"; } } if ($bitJsonResponse) { //disabled for ie. otherwise the upload won't work due to the headers. class_response_object::getInstance()->setStrResponseType(class_http_responsetypes::STR_TYPE_HTML); //class_response_object::getInstance()->setStResponseType(class_http_responsetypes::STR_TYPE_JSON); } @unlink($arrSource["tmp_name"]); return $strReturn; }
/** * 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); }
/** * 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; }
/** * Checks if all content of the passed folder is writable * @param string $strFolder * @param string[] $arrErrors */ private function checkWritableRecursive($strFolder, &$arrErrors) { if (!is_writable(_realpath_ . $strFolder)) { $arrErrors[] = $strFolder; } $objFilesystem = new class_filesystem(); $arrContent = $objFilesystem->getCompleteList($strFolder); foreach ($arrContent["files"] as $arrOneFile) { if (!is_writable(_realpath_ . $strFolder . "/" . $arrOneFile["filename"])) { $arrErrors[] = $strFolder . "/" . $arrOneFile["filename"]; } } foreach ($arrContent["folders"] as $strOneFolder) { $this->checkWritableRecursive($strFolder . "/" . $strOneFolder, $arrErrors); } }
/** * 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_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; }
/** * Fetches the latest entries from the current systemlog. * The entries can be limited by the optional param latestEntry. * If given, only entries created after the passed date will be returned. * The format of latestEntry is similar to the date returned, so YYYY-MM-DD HH:MM:SS * The structure is returned like: * <entries> * <entry> * <level></level> * <date></date> * <session></session> * <content></content> * </entry> * </entries> * * @return string * @permissions right3 */ protected function actionSystemLog() { $strReturn = ""; $intStartDate = false; if ($this->getParam("latestEntry") != "") { $intStartDate = strtotime($this->getParam("latestEntry")); } //read the last few lines $objFile = new class_filesystem(); $arrDetails = $objFile->getFileDetails("/system/debug/systemlog.log"); $intOffset = 0; $bitSkip = false; if ($arrDetails["filesize"] > 20000) { $intOffset = $arrDetails["filesize"] - 20000; $bitSkip = true; } $objFile->openFilePointer("/system/debug/systemlog.log", "r"); //forward to the new offset, skip entry if ($intOffset > 0) { $objFile->setFilePointerOffset($intOffset); } $arrRows = array(); $strRow = $objFile->readLineFromFile(); while ($strRow !== false) { if (!$bitSkip && trim($strRow) > 0) { $arrRows[] = $strRow; } $bitSkip = false; $strRow = $objFile->readLineFromFile(); } $objFile->closeFilePointer(); $strReturn .= "<entries>\n"; $arrRows = array_reverse($arrRows); foreach ($arrRows as $strSingleRow) { //parse entry $strDate = uniSubstr($strSingleRow, 0, 19); $strSingleRow = uniSubstr($strSingleRow, 20); $intTempPos = uniStrpos($strSingleRow, " "); $strLevel = uniSubstr($strSingleRow, 0, $intTempPos); $strSingleRow = uniSubstr($strSingleRow, $intTempPos + 1); $intTempPos = uniStrpos($strSingleRow, ")") + 1; $strSession = uniSubstr($strSingleRow, 0, $intTempPos); $strLogEntry = uniSubstr($strSingleRow, $intTempPos); if ($intStartDate !== false) { $intCurDate = strtotime($strDate); if ($intStartDate >= $intCurDate) { continue; } } $strReturn .= "\t<entry>\n"; $strReturn .= "\t\t<level>" . $strLevel . "</level>\n"; $strReturn .= "\t\t<date>" . $strDate . "</date>\n"; $strReturn .= "\t\t<session>" . $strSession . "</session>\n"; $strReturn .= "\t\t<content>" . xmlSafeString(strip_tags($strLogEntry)) . "</content>\n"; $strReturn .= "\t</entry>\n"; } $strReturn .= "</entries>"; return $strReturn; }
<?php echo "+-------------------------------------------------------------------------------+\n"; echo "| Kajona Debug Subsystem |\n"; echo "| |\n"; echo "| Image Viewer for Admin Skin |\n"; echo "+-------------------------------------------------------------------------------+\n"; $strIconPath = "/module_v4skin/admin/skins/kajona_v4/pics/"; echo "\nIcon-Path = " . $strIconPath . "\n"; $objFilesystem = new class_filesystem(); $arrFiles = $objFilesystem->getFilelist(class_resourceloader::getInstance()->getCorePathForModule("module_v4skin") . $strIconPath, array(".png")); echo "Found " . count($arrFiles) . "\n"; echo "<table border=0 cellpadding=2>"; foreach ($arrFiles as $strOneFile) { echo "<tr><td><img src=\"" . _webpath_ . class_resourceloader::getInstance()->getCorePathForModule("module_v4skin") . "/" . $strIconPath . $strOneFile . "\"></td>"; echo "<td>" . $strOneFile . "</td></tr>"; } echo "</table>"; echo "\n\n"; echo "+-------------------------------------------------------------------------------+\n"; echo "| (c) STB :-) |\n"; echo "+-------------------------------------------------------------------------------+\n";
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; }