Commit 6494983c authored by Henning Leutz's avatar Henning Leutz 🥋

Merge branch 'dev-844' into 'dev'

Dev 844

See merge request !12
parents 007483cd 0748abdc
......@@ -26,6 +26,14 @@ class Setup
*/
public static function all()
{
QUI\System\Log::write(
'Execute Setup',
QUI\System\Log::LEVEL_NOTICE,
[],
'setup',
true
);
QUI::getEvents()->fireEvent('setupAllBegin');
// not at phpunit
......
......@@ -33,6 +33,19 @@ class Setup extends QUI\System\Console\Tool
*/
public function execute()
{
QUI\System\Log::write(
'====== EXECUTE SETUP ======',
QUI\System\Log::LEVEL_NOTICE,
[],
'setup',
true
);
ob_start();
$this->logBuffer();
$PackageManager = QUI::getPackageManager();
$quiqqer = QUI::getPackageManager()->getPackage('quiqqer/quiqqer');
$reference = '';
......@@ -61,16 +74,37 @@ class Setup extends QUI\System\Console\Tool
$this->writeLn($data);
$this->writeLn('');
$this->writeLn(
QUI::getLocale()->get('quiqqer/quiqqer', 'console.tool.setup.start.message')
);
$this->writeLn(QUI::getLocale()->get('quiqqer/quiqqer', 'console.tool.setup.start.message'));
$this->logBuffer();
QUI\Setup::all();
$this->writeLn(
QUI::getLocale()->get('quiqqer/quiqqer', 'console.tool.setup.message.success')
);
$this->writeLn(QUI::getLocale()->get('quiqqer/quiqqer', 'console.tool.setup.message.success'));
$this->logBuffer();
$this->writeLn('');
$this->logBuffer();
}
/**
* Log the output buffer to the setup log
*/
protected function logBuffer()
{
$buffer = ob_get_contents();
$buffer = trim($buffer);
if (!empty($buffer)) {
QUI\System\Log::write(
$buffer,
QUI\System\Log::LEVEL_NOTICE,
[],
'setup',
true
);
}
flush();
ob_flush();
}
}
......@@ -16,7 +16,7 @@ use QUI;
class Update extends QUI\System\Console\Tool
{
/**
* Konstruktor
* constructor
*/
public function __construct()
{
......@@ -24,23 +24,23 @@ class Update extends QUI\System\Console\Tool
->setDescription('Update the quiqqer system and the quiqqer packages')
->addArgument(
'clearCache',
'Before execute the Update, clear the complete update cache.',
QUI::getLocale()->get('quiqqer/quiqqer', 'console.update.clearCache'),
false,
true
)
->addArgument(
'setDevelopment',
'Set QUIQQER to the development version',
QUI::getLocale()->get('quiqqer/quiqqer', 'console.update.setDevelopment'),
false,
true
)->addArgument(
'check',
'Checks for new updates',
QUI::getLocale()->get('quiqqer/quiqqer', 'console.update.check'),
false,
true
)->addArgument(
'set-date',
'Updates only the quiqqer update-date',
QUI::getLocale()->get('quiqqer/quiqqer', 'console.update.set-date'),
false,
true
);
......@@ -53,19 +53,41 @@ class Update extends QUI\System\Console\Tool
*/
public function execute()
{
$this->writeLn('- Starting Update:');
$this->writeUpdateLog('====== EXECUTE UPDATE ======');
$this->writeUpdateLog(QUI::getLocale()->get('quiqqer/quiqqer', 'update.log.message.execute.console'));
$this->writeLn(QUI::getLocale()->get('quiqqer/quiqqer', 'update.message.start'));
$this->writeLn('');
$this->logBuffer();
$self = $this;
$Packages = QUI::getPackageManager();
// output events
$Packages->getComposer()->addEvent('onOutput', function ($Composer, $output, $type) use ($self) {
$self->write($output);
$self->writeToLog($output);
});
if ($this->getArgument('set-date')) {
QUI::getPackageManager()->setLastUpdateDate();
try {
QUI::getPackageManager()->setLastUpdateDate();
$this->logBuffer();
} catch (QUI\Exception $Exception) {
$this->writeToLog('====== ERROR ======');
$this->writeToLog($Exception->getMessage());
}
return;
}
if ($this->getArgument('clearCache')) {
$Packages->clearComposerCache();
try {
$Packages->clearComposerCache();
} catch (QUI\Exception $Exception) {
$this->writeToLog('====== ERROR ======');
$this->writeToLog($Exception->getMessage());
}
}
if ($this->getArgument('setDevelopment')) {
......@@ -91,21 +113,32 @@ class Update extends QUI\System\Console\Tool
if ($this->getArgument('check')) {
$this->writeLn('Prüfe nach Aktualisierungen...'); // #locale
$this->writeLn(QUI::getLocale()->get('quiqqer/quiqqer', 'update.log.message.update.via.console'));
$this->writeLn();
$this->writeLn();
$this->logBuffer();
try {
$packages = $Packages->getOutdated(true);
} catch (\Exception $Exception) {
$this->writeToLog('====== ERROR ======');
$this->writeToLog($Exception->getMessage());
return;
}
$packages = $Packages->getOutdated(true);
$nameLength = 0;
$versionLength = 0;
// #locale
if (empty($packages)) {
$this->writeLn(
'Ihr System ist aktuell. Es wurden keine Aktualisierungen gefunden',
QUI::getLocale()->get('quiqqer/quiqqer', 'update.message.no.updates.available'),
'green'
);
$this->logBuffer();
return;
}
......@@ -131,10 +164,12 @@ class Update extends QUI\System\Console\Tool
);
$this->write($package['version'], 'cyan');
$this->writeLn();
$this->logBuffer();
}
$this->logBuffer();
return;
}
......@@ -143,8 +178,9 @@ class Update extends QUI\System\Console\Tool
$Packages->getComposer()->unmute();
$Packages->update(false, false);
$this->writeLn('- Update was executed');
$this->writeLn('- Generating Server files .htaccess and NGINX');
$this->writeLn(QUI::getLocale()->get('quiqqer/quiqqer', 'update.message.execute'));
$this->writeLn(QUI::getLocale()->get('quiqqer/quiqqer', 'update.message.webserver'));
$this->logBuffer();
$Httaccess = new Htaccess();
$Httaccess->execute();
......@@ -159,12 +195,12 @@ class Update extends QUI\System\Console\Tool
$this->write(' [error]', 'red');
$this->writeLn('');
$this->writeLn(
'Something went wrong::'.$Exception->getMessage(),
QUI::getLocale()->get('quiqqer/quiqqer', 'update.message.error.1').'::'.$Exception->getMessage(),
'red'
);
$this->writeLn(
'If the setup didn\'t worked properly, please test the following command for the update:',
QUI::getLocale()->get('quiqqer/quiqqer', 'update.message.error'),
'red'
);
......@@ -178,5 +214,57 @@ class Update extends QUI\System\Console\Tool
$this->resetColor();
$this->writeLn('');
}
$this->logBuffer();
}
/**
* Write a log to the update file
*
* @param string $message
*/
protected function writeUpdateLog($message)
{
QUI\System\Log::write(
$message,
QUI\System\Log::LEVEL_NOTICE,
[
'params' => [
'clearCache' => $this->getArgument('clearCache'),
'setDevelopment' => $this->getArgument('setDevelopment'),
'check' => $this->getArgument('check'),
'set-date' => $this->getArgument('set-date')
]
],
'update',
true
);
}
/**
* Log the output buffer to the update log
*/
protected function logBuffer()
{
$buffer = \ob_get_contents();
$buffer = \trim($buffer);
$this->writeToLog($buffer);
@\flush();
@\ob_flush();
}
/**
* Write buffer to the update log
*
* @param string $buffer
*/
protected function writeToLog($buffer)
{
if (empty($buffer)) {
return;
}
\error_log($buffer, 3, VAR_DIR.'log/update.log');
}
}
......@@ -87,9 +87,7 @@ class Log
return;
}
if (isset($_SERVER['REQUEST_URI'])
&& !empty($_SERVER['REQUEST_URI'])
) {
if (isset($_SERVER['REQUEST_URI']) && !empty($_SERVER['REQUEST_URI'])) {
$context['request'] = HOST.$_SERVER['REQUEST_URI'];
}
......
......@@ -654,4 +654,14 @@ class Update
self::importLocale(\trim($file));
}
}
/**
* Returns the current update log file
*
* @return string
*/
public static function getLogFile()
{
return VAR_DIR.'log/error'.date('-Y-m-d').'.log';
}
}
......@@ -1235,6 +1235,45 @@
<locale name="exception.crud.child.not.found">
<de><![CDATA[Der Eintrag konnte nicht gefunden werden.]]></de>
</locale>
<locale name="update.log.message.execute.console">
<de><![CDATA[Update wird über die Konsole ausgeführt.]]></de>
</locale>
<locale name="update.log.message.update.via.console">
<de><![CDATA[Prüfe nach Aktualisierungen...]]></de>
</locale>
<locale name="update.message.start">
<de><![CDATA[- Starte Update:]]></de>
</locale>
<locale name="update.message.execute">
<de><![CDATA[- Die Aktualisierung wurde durchgeführt]]></de>
</locale>
<locale name="update.message.webserver">
<de><![CDATA[- Generiere Server dateien .htaccess und NGINX]]></de>
</locale>
<locale name="update.message.no.updates.available">
<de><![CDATA[Dein System ist aktuell. Es wurden keine Aktualisierungen gefunden.]]></de>
</locale>
<locale name="update.message.error">
<de>
<![CDATA[Wenn das Setup nicht richtig funktioniert hat, nutze bitte den folgenden Befehl für das Update:]]></de>
</locale>
<locale name="update.message.error.1">
<de><![CDATA[Etwas ist schief gelaufen]]></de>
</locale>
<locale name="console.update.clearCache">
<de><![CDATA[Leere vor dem Ausführen des Updates den gesamten Update-Cache.]]></de>
</locale>
<locale name="console.update.setDevelopment">
<de><![CDATA[QUIQQQER auf die Entwicklungsversion setzen.]]></de>
</locale>
<locale name="console.update.check">
<de><![CDATA[Überprüfe auf neue Updates.]]></de>
</locale>
<locale name="console.update.set-date">
<de><![CDATA[Aktualisiert nur das quiqqer Update-Datum.]]></de>
</locale>
<locale name="user.settings.showNamesInSitemap">
<de><![CDATA[Seitennamen in der Sitemap anzeigen]]></de>
</locale>
......
......@@ -1226,6 +1226,44 @@
<locale name="exception.crud.child.not.found">
<en><![CDATA[The entry could not be found.]]></en>
</locale>
<locale name="update.log.message.execute.console">
<en><![CDATA[Update is executed via the console.]]></en>
</locale>
<locale name="update.log.message.update.via.console">
<en><![CDATA[Check for updates...]]></en>
</locale>
<locale name="update.message.start">
<en><![CDATA[- Starting Update:]]></en>
</locale>
<locale name="update.message.execute">
<en><![CDATA[- Update was executed]]></en>
</locale>
<locale name="update.message.webserver">
<en><![CDATA[- Generating Server files .htaccess and NGINX]]></en>
</locale>
<locale name="update.message.no.updates.available">
<en><![CDATA[Your system is up to date. No updates found.]]></en>
</locale>
<locale name="update.message.error">
<en><![CDATA[If the setup didn't worked properly, please test the following command for the update:]]></en>
</locale>
<locale name="update.message.error.1">
<en><![CDATA[Something went wrong]]></en>
</locale>
<locale name="console.update.clearCache">
<en><![CDATA[Before execute the Update, clear the complete update cache.]]></en>
</locale>
<locale name="console.update.setDevelopment">
<en><![CDATA[Set QUIQQER to the development version.]]></en>
</locale>
<locale name="console.update.check">
<en><![CDATA[Checks for new updates.]]></en>
</locale>
<locale name="console.update.set-date">
<en><![CDATA[Updates only the quiqqer update-date.]]></en>
</locale>
<locale name="user.settings.showNamesInSitemap">
<en><![CDATA[Show site names in the sitemap]]></en>
</locale>
......
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