/** * 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 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]); }
/** * 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; }
/** * 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; }
/** * 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; }
/** * @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; }
<?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";
/** * Dumps the current db * Takes care of holding just the defined number of dumps in the filesystem, defined by _system_dbdump_amount_ * * @param array $arrTablesToExclude specify a set of tables not to be included in the dump * * @return bool */ public function dumpDb($arrTablesToExclude = array()) { if (!$this->bitConnected) { $this->dbconnect(); } // Check, how many dumps to keep $objFilesystem = new class_filesystem(); $arrFiles = $objFilesystem->getFilelist(_projectpath_ . "/dbdumps/", array(".sql", ".gz")); while (count($arrFiles) >= class_module_system_setting::getConfigValue("_system_dbdump_amount_")) { $strFile = array_shift($arrFiles); if (!$objFilesystem->fileDelete(_projectpath_ . "/dbdumps/" . $strFile)) { class_logger::getInstance(class_logger::DBLOG)->addLogRow("Error deleting old db-dumps", class_logger::$levelWarning); return false; } $arrFiles = $objFilesystem->getFilelist(_projectpath_ . "/dbdumps/", array(".sql", ".gz")); } $strTargetFilename = _projectpath_ . "/dbdumps/dbdump_" . time() . ".sql"; $arrTables = $this->getTables(); $arrTablesFinal = array(); if (count($arrTablesToExclude) > 0) { foreach ($arrTables as $strOneTable) { if (!in_array(uniStrReplace(_dbprefix_, "", $strOneTable), $arrTablesToExclude)) { $arrTablesFinal[] = $strOneTable; } } } else { $arrTablesFinal = $arrTables; } $bitDump = $this->objDbDriver->dbExport($strTargetFilename, $arrTablesFinal); if ($bitDump == true) { $objGzip = new class_gzip(); try { if (!$objGzip->compressFile($strTargetFilename, true)) { class_logger::getInstance(class_logger::DBLOG)->addLogRow("Failed to compress (gzip) the file " . basename($strTargetFilename) . "", class_logger::$levelWarning); } } catch (class_exception $objExc) { $objExc->processException(); } } if ($bitDump) { class_logger::getInstance(class_logger::DBLOG)->addLogRow("DB-Dump " . basename($strTargetFilename) . " created", class_logger::$levelInfo); } else { class_logger::getInstance(class_logger::DBLOG)->addLogRow("Error creating " . basename($strTargetFilename), class_logger::$levelError); } return $bitDump; }
/** * Internal helper, fetches all installers located within the passed package * * @param class_module_packagemanager_metadata $objMetadata * * @return interface_installer[] */ private function getInstaller(class_module_packagemanager_metadata $objMetadata) { $objFilesystem = new class_filesystem(); $arrInstaller = $objFilesystem->getFilelist($objMetadata->getStrPath() . "/installer/", array(".php")); if ($arrInstaller === false) { return array(); } $arrReturn = array(); //start with modules foreach ($arrInstaller as $strOneInstaller) { //skip samplecontent files if (uniStrpos($strOneInstaller, "class_") === false || uniStrpos($strOneInstaller, "installer") === false || uniStrpos($strOneInstaller, "_sc_") !== false) { continue; } $strName = uniSubstr($strOneInstaller, 0, -4); /** @var $objInstaller interface_installer */ $objInstaller = new $strName(); $arrReturn[] = $objInstaller; } return $arrReturn; }
/** * Fetches the entries from the system-log an prints them as preformatted text * * @return string * @autoTestable * @permissions right3 */ protected function actionSystemlog() { //load logfiles available $objFilesystem = new class_filesystem(); $arrFiles = $objFilesystem->getFilelist(_projectpath_ . "/log", array(".log")); $arrTabs = array(); foreach ($arrFiles as $strName) { $objFilesystem->openFilePointer(_projectpath_ . "/log/" . $strName, "r"); $strLogContent = $objFilesystem->readLastLinesFromFile(20); $strLogContent = str_replace(array("INFO", "ERROR"), array("INFO ", "ERROR "), $strLogContent); $arrLogEntries = explode("\r", $strLogContent); $objFilesystem->closeFilePointer(); $arrTabs[$strName] = $this->objToolkit->getPreformatted($arrLogEntries); } return $this->objToolkit->getTabbedContent($arrTabs); }
echo "+-------------------------------------------------------------------------------+\n"; if (issetPost("doimport")) { $strFilename = getPost("dumpname"); $objDb = class_carrier::getInstance()->getObjDB(); echo "importing " . $strFilename . "\n"; if ($objDb->importDb($strFilename)) { echo "\n<span style='color: green;font-weight:bold;'>import successfull.</span>\n"; } else { echo "\n<span style='color: red;font-weight:bold;'>import failed!!</span>\n"; } } else { echo "Searching for dumps in dbdumps under: " . _projectpath_ . "\n"; $objFilesystem = new class_filesystem(); if ($objFilesystem->isWritable("/project/dbdumps")) { echo "Searching dbdumps available...\n"; $arrFiles = $objFilesystem->getFilelist(_projectpath_ . "/dbdumps/", array(".zip", ".gz", ".sql")); echo "Found " . count($arrFiles) . " dump(s)\n\n"; echo "<form method='post'>"; echo "Dump to import:\n"; $arrImportfileData = array(); foreach ($arrFiles as $strOneFile) { $strFileInfo = ""; $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)) { //if the timestamp is the last part of the filename, we can use $strTimestamp $strFileInfo = $strOneFile . " (" . bytesToString($arrDetails['filesize']) . ")" . "\n Timestamp according to file name: " . timeToString($strTimestamp) . "\n Timestamp according to file info: " . timeToString($arrDetails['filechange']); } else {