Commit 0f243da2 authored by Marc Egger's avatar Marc Egger

replace some system path constants with Path::

parent 1800c286
Pipeline #3843 failed with stages
in 2 minutes and 54 seconds
......@@ -549,15 +549,10 @@ const SYSTEM_FORM_BS_NOTE_COLUMNS = 'formBsNoteColumns';
const SYSTEM_BASE_URL = 'baseUrl';
const SYSTEM_SEND_E_MAIL_ABSOLUTE = 'sendEmail';
const SYSTEM_SEND_E_MAIL_OPTIONS = 'sendEMailOptions';
const SYSTEM_EDIT_FORM_PAGE = 'editFormPage';
// computed automatically during runtime
const SYSTEM_EXT_PATH_ABSOLUTE = 'extPath';
const SYSTEM_SITE_PATH_ABSOLUTE = 'sitePath'; // Path of the App
const SYSTEM_LDAP_1_RDN = 'LDAP_1_RDN'; // Credentials to access LDAP
const SYSTEM_LDAP_1_PASSWORD = 'LDAP_1_PASSWORD'; // Credentials to access LDAP
......
......@@ -194,7 +194,7 @@ $UPDATE_ARRAY = array(
"ALTER TABLE `FormElement` CHANGE `label` `label` VARCHAR(1023) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '';",
],
'20.7.0' => [
'20.X.0' => [ // TODO: replace X with newest version number
"ALTER TABLE `Form` ADD `fileStats` VARCHAR(255) NOT NULL DEFAULT '' AFTER `created`;",
],
);
......
......@@ -9,6 +9,7 @@
namespace IMATHUZH\Qfq\Core;
use IMATHUZH\Qfq\Core\Database\Database;
use IMATHUZH\Qfq\Core\Helper\Path;
use IMATHUZH\Qfq\Core\Store\Store;
use IMATHUZH\Qfq\Core\Helper\HelperFile;
......@@ -70,7 +71,7 @@ class Delete {
// Take care the necessary target directories exist.
$cwd = getcwd();
$sitePath = $this->store->getVar(SYSTEM_SITE_PATH_ABSOLUTE, STORE_SYSTEM);
$sitePath = Path::absoluteApp();
if ($cwd === false || $sitePath === false || !HelperFile::chdir($sitePath)) {
throw new \UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'getcwd() failed or SITE_PATH undefined or chdir() failed', ERROR_MESSAGE_TO_DEVELOPER => "getcwd() failed or SITE_PATH undefined or chdir('$sitePath') failed."]),
......
......@@ -100,6 +100,9 @@ class Path
const APP_TO_SYSTEM_THUMBNAIL_DIR_PUBLIC_DEFAULT = 'typo3temp/qfqThumbnail';
const APP_TO_THUMBNAIL_UNKNOWN_TYPE = 'typo3/sysext/frontend/Resources/Public/Icons/FileIcons/';
// Send Email
const EXT_TO_SEND_EMAIL_FILE = '/Classes/External/sendEmail';
/**
* @param string $cwdToApp
* @throws \CodeException
......@@ -112,6 +115,24 @@ class Path
self::findAndSetLogPath();
}
/**
* @return string
* @throws \UserFormException
*/
public static function absoluteApp(/* path parts to append */): string
{
return realpath(self::cwdToApp(func_get_args()));
}
/**
* @return string
* @throws \UserFormException
*/
public static function absoluteExt(/* path parts to append */): string
{
return realpath(self::cwdToExt(func_get_args()));
}
/**
* @return string
* @throws \UserFormException
......
......@@ -543,7 +543,7 @@ class Download {
$srcFiles = array();
$filesCleanLater = array();
$workDir = $this->store->getVar(SYSTEM_SITE_PATH_ABSOLUTE, STORE_SYSTEM);
$workDir = Path::absoluteApp();
HelperFile::chdir($workDir);
$downloadMode = $vars[DOWNLOAD_MODE];
......
......@@ -221,7 +221,7 @@ class SendMail {
$args[] = '-o message-header="' . $mailConfig[SENDMAIL_TOKEN_HEADER] . '"';
}
$sendEmail = $this->store->getVar(SYSTEM_SEND_E_MAIL_ABSOLUTE, STORE_SYSTEM);
$sendEmail = Path::absoluteExt(Path::EXT_TO_SEND_EMAIL_FILE);
if (empty($sendEmail)) {
throw new \UserFormException("Missing 'sendEmail'", ERROR_SENDMAIL);
}
......
......@@ -495,7 +495,7 @@ class Save {
// Upload - Take care the necessary target directories exist.
$cwd = getcwd();
$sitePath = $this->store->getVar(SYSTEM_SITE_PATH, STORE_SYSTEM);
$sitePath = Path::cwdToApp();
if ($cwd === false || $sitePath === false || !HelperFile::chdir($sitePath)) {
throw new \UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'getcwd() failed or SITE_PATH undefined or chdir() failed', ERROR_MESSAGE_TO_DEVELOPER => "getcwd() failed or SITE_PATH undefined or chdir('$sitePath') failed."]),
......@@ -780,7 +780,7 @@ class Save {
// Take care the necessary target directories exist.
$cwd = getcwd();
$sitePath = $this->store->getVar(SYSTEM_SITE_PATH_ABSOLUTE, STORE_SYSTEM);
$sitePath = Path::absoluteApp();
if ($cwd === false || $sitePath === false || !HelperFile::chdir($sitePath)) {
throw new \UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'getcwd() failed or SITE_PATH undefined or chdir() failed', ERROR_MESSAGE_TO_DEVELOPER => "getcwd() failed or SITE_PATH undefined or chdir('$sitePath') failed."]),
......
......@@ -241,48 +241,6 @@ class Store {
return self::$instance;
}
/**
* QFQ might be called via Typo3 (index.php) or directly via AJAX (directory: api). The
*
* @param array $config
*
* @return array
*/
private static function doSystemPath(array $config) {
// SYSTEM_PATH_EXT: compute only if not already defined.
if (!isset($config[SYSTEM_EXT_PATH_ABSOLUTE]) || $config[SYSTEM_EXT_PATH_ABSOLUTE] === '' || $config[SYSTEM_EXT_PATH_ABSOLUTE][0] !== '/') {
$relExtDir = '/typo3conf/ext/' . EXT_KEY;
if (defined('PHPUNIT_QFQ')) {
$cwd = getcwd();
$pos = strpos($cwd, '/typo3conf/');
// this means phpUnit.
$config[SYSTEM_SITE_PATH_ABSOLUTE] = substr($cwd, 0, $pos);
$config[SYSTEM_EXT_PATH_ABSOLUTE] = $config[SYSTEM_SITE_PATH_ABSOLUTE] . $relExtDir;
} else {
// If we are called through AJAX API (e.g. api/save.php), there is no TYPO3 environment.
$pos = strpos($_SERVER['SCRIPT_FILENAME'] ?? '', $relExtDir);
if ($pos === false && isset($GLOBALS['TYPO3_LOADED_EXT'][EXT_KEY]['ext_localconf.php'])) {
// Typo3 extension: probably index.php
$config[SYSTEM_EXT_PATH_ABSOLUTE] = dirname($GLOBALS['TYPO3_LOADED_EXT'][EXT_KEY]['ext_localconf.php']);
$config[SYSTEM_SITE_PATH_ABSOLUTE] = dirname($_SERVER['SCRIPT_FILENAME'] ?? '');
} else {
// API
$config[SYSTEM_EXT_PATH_ABSOLUTE] = substr($_SERVER['SCRIPT_FILENAME'] ?? '', 0, $pos + strlen($relExtDir));
$config[SYSTEM_SITE_PATH_ABSOLUTE] = substr($_SERVER['SCRIPT_FILENAME'] ?? '', 0, $pos);
}
}
}
Logger::setSystemSitePathAbsolute($config[SYSTEM_SITE_PATH_ABSOLUTE]);
return $config;
}
/**
* Depending on some configuration value, update corresponding values.
*
......@@ -294,8 +252,6 @@ class Store {
$config[SYSTEM_SHOW_DEBUG_INFO] = self::adjustConfigShowDebugInfo($config[SYSTEM_SHOW_DEBUG_INFO], self::beUserLoggdIn());
$config[SYSTEM_SEND_E_MAIL_ABSOLUTE] = $config[SYSTEM_EXT_PATH_ABSOLUTE] . '/Classes/External/sendEmail';
// In case the database credentials are given in the old style: copy them to the new style
if (!isset($config[SYSTEM_DB_1_USER]) && isset($config[SYSTEM_DB_USER])) {
$config[SYSTEM_DB_1_USER] = $config[SYSTEM_DB_USER];
......@@ -461,7 +417,6 @@ class Store {
$config = Config::readConfig($PhpUnitOverloadCwdToConfigFile);
$config = self::doSystemPath($config);
$config = self::adjustConfig($config);
$config = self::setAutoConfigValue($config);
......
......@@ -13,6 +13,7 @@ use IMATHUZH\Qfq\Core\Database\Database;
use IMATHUZH\Qfq\Core\Evaluate;
use IMATHUZH\Qfq\Core\Helper\DownloadPage;
use IMATHUZH\Qfq\Core\Helper\Logger;
use IMATHUZH\Qfq\Core\Helper\Path;
use IMATHUZH\Qfq\Core\Helper\Support;
use IMATHUZH\Qfq\Core\Report\SendMail;
use IMATHUZH\Qfq\Core\Store\Store;
......@@ -175,7 +176,7 @@ class AutoCron {
// If configured, log the download content
if (!empty($job[AUTOCRON_OUTPUT_FILE])) {
$job[AUTOCRON_OUTPUT_FILE] = Support::joinPath($this->store->getVar(SYSTEM_SITE_PATH_ABSOLUTE, STORE_SYSTEM), $job[AUTOCRON_OUTPUT_FILE], FILE_PRIORITY);
$job[AUTOCRON_OUTPUT_FILE] = Support::joinPath(Path::absoluteApp(), $job[AUTOCRON_OUTPUT_FILE], FILE_PRIORITY);
Logger::logMessage($page, $job[AUTOCRON_OUTPUT_FILE], $job[AUTOCRON_OUTPUT_MODE] == 'append' ? FILE_MODE_APPEND : FILE_MODE_WRITE);
}
......
......@@ -58,6 +58,7 @@ use IMATHUZH\Qfq\Core\QuickFormQuery;
// Before production
// TODO: switch qfq.debug.js with qfq.min.js
// TODO: DatabaseUpdateData.php move updates from '20.X.0' to newest
////
......
......@@ -9,6 +9,7 @@
namespace IMATHUZH\Qfq\Tests\Unit\Core;
use IMATHUZH\Qfq\Core\Delete;
use IMATHUZH\Qfq\Core\Helper\Path;
use IMATHUZH\Qfq\Core\Store\Store;
use IMATHUZH\Qfq\Tests\Unit\Core\Database\AbstractDatabaseTest;
......@@ -73,7 +74,10 @@ class DeleteTest extends AbstractDatabaseTest {
parent::setUp();
$this->store->setVar('form', 'TestFormName', STORE_TYPO3);
$this->store->setVar(SYSTEM_SITE_PATH_ABSOLUTE, '/tmp', STORE_SYSTEM, true);
Path::setMainPaths('/tmp');
// The above replaces the following line with a Path:: function. Probably won't work.
// $this->store->setVar(SYSTEM_SITE_PATH_ABSOLUTE, '/tmp', STORE_SYSTEM, true);
$this->executeSQLFile(__DIR__ . '/Database/fixtures/Generic.sql', true);
}
......
......@@ -444,7 +444,7 @@ class StoreTest extends TestCase {
$config = $this->store->getStore(STORE_SYSTEM);
# The following won't be checked by content, cause they will change on different installations.
foreach ([SYSTEM_SITE_PATH_ABSOLUTE, SYSTEM_EXT_PATH_ABSOLUTE, SYSTEM_SEND_E_MAIL_ABSOLUTE, SYSTEM_SESSION_TIMEOUT_SECONDS, SYSTEM_QFQ_LOG_PATHFILENAME,
foreach ([SYSTEM_SESSION_TIMEOUT_SECONDS, SYSTEM_QFQ_LOG_PATHFILENAME,
SYSTEM_SQL_LOG_PATHFILENAME, SYSTEM_MAIL_LOG_PATHFILENAME, SYSTEM_FILE_MAX_FILE_SIZE] as $key) {
$this->assertTrue(isset($config[$key]), "Missing default value for '$key' ");
unset ($config[$key]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment