Commit 7ad2482c authored by Damjan's avatar Damjan

[TASK] General layout - saving metadata

- Implementation of generalSaveAction
- Addition of meta information in general template
- Rename: MainService -> ConfigurationService
- Introduction of AbstractService which contains object manager and session
- Introduction of BackupService (not used yet)
- Addition of Lfeditor.css

Related: forge.typo3.org/issues/31889
parent e781394d
......@@ -26,6 +26,7 @@ namespace SGalinski\Lfeditor\Controller;
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use SGalinski\Lfeditor\Exceptions\LFException;
use SGalinski\Lfeditor\Service\BackupService;
use SGalinski\Lfeditor\Utility\Functions;
use TYPO3\CMS\Core\Messaging\AbstractMessage;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
......@@ -36,9 +37,9 @@ use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
class MainController extends AbstractController {
/**
* @inject
* @var \SGalinski\Lfeditor\Service\MainService
* @var \SGalinski\Lfeditor\Service\ConfigurationService
*/
protected $mainService;
protected $configurationService;
/**
* Initializes the actions.
......@@ -49,7 +50,7 @@ class MainController extends AbstractController {
*/
public function initializeAction() {
parent::initializeAction();
$this->mainService->prepareConfig();
$this->configurationService->prepareConfig();
}
/**
......@@ -58,11 +59,11 @@ class MainController extends AbstractController {
* @return void
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException //TODO: Handle every exception in controllers and display flash message.
*/
public function initializeLfeditorAction() {
// //TODO: I might not need this. I am preparing config in every request before every action...
// $this->mainService->prepareConfig();
$this->redirect('general');
}
// public function initLfeditorAction() {
//// //TODO: I might not need this. I am preparing config in every request before every action...
//// $this->configurationService->prepareConfig();
// $this->redirect('general');
// }
/**************************************
* Actions called from general view *
......@@ -80,22 +81,22 @@ class MainController extends AbstractController {
$this->view->assign('mainMenuSelection', 'general');
try {
$extensionOptions = $this->mainService->menuExtList();
$extensionOptions = $this->configurationService->menuExtList();
$this->assignViewWidthMenuVariables('extension', $extensionOptions);
//TODO: In same way (like extension menu) handle all other select menus that exist in the view
$languageFileOptions = $this->mainService->menuLangFileList(
$languageFileOptions = $this->configurationService->menuLangFileList(
$this->session->getDataByKey('extensionSelection')
);
$this->assignViewWidthMenuVariables('languageFile', $languageFileOptions);
$this->mainService->initFileObject(
$this->configurationService->initFileObject(
$this->session->getDataByKey('languageFileSelection'),
$this->session->getDataByKey('extensionSelection')
);
$referenceLanguageOptions = $this->mainService->menuLangList(
$this->mainService->getFileObj()->getLocalLangData()
$referenceLanguageOptions = $this->configurationService->menuLangList(
$this->configurationService->getFileObj()->getLocalLangData()
);
$this->assignViewWidthMenuVariables('referenceLanguage', $referenceLanguageOptions);
......@@ -147,14 +148,69 @@ class MainController extends AbstractController {
/**
* Saves the changes made in main section of general view.
*
* @return void
* @param string $metaTypeSelection
* @param string $metaCSHTable
* @param string $authorName
* @param string $authorEmail
* @param string $metaDescription
* @param string $transformFile
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException
* @return void
*/
public function generalSaveAction() {
//TODO: Delete. test $this->session->destroy();
//TODO: Save the changes.
$this->session->destroy();
debug(phpinfo(), 'phpInfo');
public function generalSaveAction(
$metaTypeSelection = NULL, $metaCSHTable = NULL, $authorName = NULL, $authorEmail = NULL,
$metaDescription = NULL, $transformFile = NULL
) {
try {
$fileObject = $this->configurationService->getFileObj();
if ($fileObject == NULL) {
$this->configurationService->initFileObject(
$this->session->getDataByKey('languageFileSelection'),
$this->session->getDataByKey('extensionSelection')
);
$fileObject = $this->configurationService->getFileObj();
}
if ($this->configurationService->getExtConfig()['execBackup']) {
/** @var BackupService $backupService */
$backupService = $this->objectManager->get('SGalinski\Lfeditor\Service\BackupService');
// $backupService->execBackup(); //TODO: make backup work.
}
$fileObject->setMetaData('type', $metaTypeSelection);
$fileObject->setMetaData('csh_table', $metaCSHTable);
$fileObject->setMetaData('authorName', $authorName);
$fileObject->setMetaData('authorEmail', $authorEmail);
$fileObject->setMetaData('description', $metaDescription);
$fileObject->writeFile();
//TODO: Make file transformation here or in seperate form/action if possible.
$this->configurationService->initFileObject(
$this->session->getDataByKey('languageFileSelection'),
$this->session->getDataByKey('extensionSelection')
);
} catch (LFException $e) {
if ($e->getCode() == 0) {
$this->addFlashMessage(
$e->getMessage(),
$messageTitle = LocalizationUtility::translate('failure.failure', 'lfeditor'),
$severity = AbstractMessage::ERROR,
$storeInSession = TRUE
);
} else {
if ($e->getCode() == 1) {
$this->addFlashMessage(
$e->getMessage(),
$messageTitle = 'Notification', //TODO: Need to be added in lang file.
$severity = AbstractMessage::NOTICE,
$storeInSession = TRUE
);
}
}
}
$this->redirect('general');
}
......@@ -165,22 +221,22 @@ class MainController extends AbstractController {
* @return void
*/
protected function prepareGeneralViewMainSectionContent($referenceLanguageSelection) {
$numTextAreaRows = $this->mainService->getExtConfig()['numTextAreaRows'];
$langArray = $this->mainService->getLangArray();
$numTextAreaRows = $this->configurationService->getExtConfig()['numTextAreaRows'];
$langArray = $this->configurationService->getLangArray();
$infoArray = Functions::genGeneralInfoArray(
$referenceLanguageSelection,
$langArray, $this->mainService->getFileObj()
$langArray, $this->configurationService->getFileObj()
);
$description = $infoArray['default']['meta']['description'];
$description = preg_replace('/<br.*>/U', "\n", $description);
$this->view->assign('infos', $infoArray);
$this->view->assign('metaTypeSelection', $infoArray['default']['meta']['type']);
$this->view->assign('metaCSHTableValue', $infoArray['default']['meta']['csh_table']);
$this->view->assign('authorNameValue', $infoArray['default']['meta']['authorName']);
$this->view->assign('authorEmailValue', $infoArray['default']['meta']['authorEmail']);
$this->view->assign('metaCSHTable', $infoArray['default']['meta']['csh_table']);
$this->view->assign('authorName', $infoArray['default']['meta']['authorName']);
$this->view->assign('authorEmail', $infoArray['default']['meta']['authorEmail']);
$this->view->assign('numTextAreaRows', $numTextAreaRows);
$this->view->assign('description', $description);
$this->view->assign('metaDescription', $description);
// // get output
// $email = '';
......
<?php
namespace SGalinski\Lfeditor\Service;
/***************************************************************
* Copyright notice
*
* (c) sgalinski Internet Services (http://www.sgalinski.de)
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use SGalinski\Lfeditor\Session\PhpSession;
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
abstract class AbstractService implements SingletonInterface {
/**
* @var \TYPO3\CMS\Extbase\Object\ObjectManager
*/
protected $objectManager;
/**
* @var \SGalinski\Lfeditor\Session\PhpSession
*/
protected $session;
function __construct() {
$this->objectManager = GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager');
}
/**
* Initializes the session object.
*
* @return void
*/
public function initializeObject() {
if (!($this->session instanceof PhpSession)) {
$this->session = $this->objectManager->get('SGalinski\Lfeditor\Session\PhpSession');
$this->session->setSessionKey('tx_lfeditor_menuSelections');
}
}
}
\ No newline at end of file
<?php
namespace SGalinski\Lfeditor\Service;
/***************************************************************
* Copyright notice
*
* (c) sgalinski Internet Services (http://www.sgalinski.de)
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use Exception;
use SGalinski\Lfeditor\Exceptions\LFException;
use SGalinski\Lfeditor\Utility\Functions;
use SGalinski\Lfeditor\Utility\SgLib;
use SGalinski\Lfeditor\Utility\Typo3Lib;
class BackupService extends AbstractService {
/**
* @var FileBackupService
*/
private $backupObj;
/**
* init backup object
*
* @throws LFException raised if directories cant be created or backup class instantiated
* @throws Exception|LFException
* @param string $mode workspace
* @param boolean|array $infos set to true if you want use information from the file object
* @return void
*/
private function initBackupObject($mode = 'base', $infos = NULL) {
$mode = ($mode ?: 'base');
/** @var ConfigurationService $confService */
$confService = $this->objectManager->get('SGalinski\Lfeditor\Service\ConfigurationService');
// create backup and meta directory
$backupPath = $confService->getExtConfig()['pathBackup'];
$metaFile = $confService->getExtConfig()['metaFile'];
try {
SgLib::createDir($backupPath, PATH_site);
SgLib::createDir(dirname($metaFile), PATH_site);
} catch (Exception $e) {
throw new LFException('failure.failure', 0, '(' . $e->getMessage() . ')');
}
// get information
$extPath = '';
$langFile = '';
if (!is_array($infos)) {
// build language file and extension path
if ($mode == 'xll') {
try {
$typo3RelFile = $confService->getFileObj()->getVar('typo3RelFile');
$typo3AbsFile = Typo3Lib::transTypo3File($typo3RelFile, TRUE);
} catch (Exception $e) {
throw new LFException('failure.failure', 0, '(' . $e->getMessage() . ')');
}
$langFile = SgLib::trimPath('EXT:', $typo3RelFile);
$langFile = substr($langFile, strpos($langFile, '/') + 1);
$extPath = SgLib::trimPath(
$langFile, SgLib::trimPath(
PATH_site,
$typo3AbsFile
), '/'
);
} else {
$extPath = SgLib::trimPath(PATH_site, $confService->getFileObj()->getVar('absPath'), '/');
$langFile = $confService->getFileObj()->getVar('relFile');
}
// set data information
$informations['localLang'] = $confService->getFileObj()->getLocalLangData();
$informations['originLang'] = $confService->getFileObj()->getOriginLangData();
$informations['meta'] = $confService->getFileObj()->getMetaData();
}
// set information
$informations['workspace'] = $mode;
$informations['extPath'] = is_array($infos) ? $infos['extPath'] : $extPath;
$informations['langFile'] = is_array($infos) ? $infos['langFile'] : $langFile;
// create and initialize the backup object
try {
$this->backupObj = $this->objectManager->get('SGalinski\Lfeditor\Service\FileBackupService');
$this->backupObj->init('', $backupPath, $metaFile);
$this->backupObj->setVar($informations);
} catch (LFException $e) {
throw $e;
}
}
/**
* executes the deletion of backup files
*
* @throws LFException raised if a backup file couldnt be deleted
* @param array $delFiles files as key and the language file as value
* @return void
*/
public function execBackupDelete($delFiles) {
// delete files
try {
foreach ($delFiles as $filename => $langFile) {
$this->backupObj->deleteSpecFile($filename, '', $langFile);
}
} catch (LFException $e) {
throw $e;
}
}
/**
* restores a backup file
*
* @throws LFException raised if some unneeded files couldnt be deleted
* @throws Exception|LFException
* @return void
*/
public function execBackupRestore() {
/** @var ConfigurationService $confService */
$confService = $this->objectManager->get('SGalinski\Lfeditor\Service\ConfigurationService');
// get vars
$localLang = [];
$meta = [];
$origLang = $confService->getFileObj()->getLocalLangData();
$origMeta = $confService->getFileObj()->getMetaData();
$backupMeta = $this->backupObj->getMetaData();
$backupLocalLang = $this->backupObj->getLocalLangData();
$backupOriginLang = $this->backupObj->getOriginLangData();
// get differences between original and backup file
$origDiff = Functions::getBackupDiff(1, $origLang, $backupLocalLang);
$backupDiff = Functions::getBackupDiff(2, $origLang, $backupLocalLang);
if (count($origDiff)) {
foreach ($origDiff as $langKey => $data) {
foreach ($data as $label => $value) {
if (isset($backupLocalLang[$langKey][$label])) {
$localLang[$langKey][$label] = $value;
} else {
$localLang[$langKey][$label] = '';
}
}
}
}
if (count($backupDiff)) {
foreach ($backupDiff as $langKey => $data) {
foreach ($data as $label => $value) {
$localLang[$langKey][$label] = $value;
}
}
}
// get differences between original and backup meta
$origDiff = Functions::getMetaDiff(1, $origMeta, $backupMeta);
$backupDiff = Functions::getMetaDiff(2, $origMeta, $backupMeta);
if (count($origDiff)) {
foreach ($origDiff as $label => $value) {
if (isset($backupMeta[$label])) {
$meta[$label] = $value;
} else {
$meta[$label] = '';
}
}
}
if (count($backupDiff)) {
foreach ($backupDiff as $label => $value) {
$meta[$label] = $value;
}
}
// restore origins of languages
$deleteFiles = [];
foreach ($backupOriginLang as $langKey => $file) {
$curFile = $confService->getFileObj()->getOriginLangData($langKey);
if ($curFile != $file && $curFile != $confService->getFileObj()->getVar('absFile')) {
$deleteFiles[] = $curFile;
}
$confService->getFileObj()->setOriginLangData($file, $langKey);
}
// write modified language array
try {
$confService->getExtConfig()['execBackup'] = 0;
$this->execWrite($localLang, $meta, TRUE);
} catch (LFException $e) {
throw $e;
}
// delete all old files
try {
if (count($deleteFiles)) {
SgLib::deleteFiles($deleteFiles);
}
} catch (Exception $e) {
throw new LFException(
'failure.langfile.notDeleted', 0,
'(' . $e->getMessage() . ')'
);
}
}
/**
* exec the backup of files and deletes automatic old files
*
* @throws LFException raised if backup file cant written or unneeded files cant deleted
* @return boolean
*/
public function execBackup() {
/** @var ConfigurationService $confService */
$confService = $this->objectManager->get('SGalinski\Lfeditor\Service\ConfigurationService');
// create backup object
try {
$this->initBackupObject('base', TRUE);
} catch (LFException $e) {
throw $e;
}
// write backup file
try {
$this->backupObj->writeFile();
} catch (LFException $e) {
throw $e;
}
// exec automatic deletion of backup files, if anzBackup greater zero
if ($confService->getExtConfig()['anzBackup'] <= 0) {
return TRUE;
}
// get difference information
$metaArray = $this->backupObj->getMetaInfos(3);
$rows = count($metaArray);
$dif = $rows - $confService->getExtConfig()['anzBackup'];
if ($dif <= 0) {
return TRUE;
}
// sort metaArray
foreach ($metaArray as $key => $row) {
$createdAt[$key] = $row['createdAt'];
}
array_multisort($createdAt, SORT_DESC, $metaArray);
// get filenames
$files = array_keys($metaArray);
$numberFiles = count($files);
// delete files
try {
for (; $dif > 0; --$dif, --$numberFiles) {
$this->backupObj->deleteSpecFile($files[$numberFiles - 1]);
}
} catch (LFException $e) {
try { // delete current written file
$this->backupObj->deleteFile();
} catch (LFException $e) {
throw $e;
}
throw $e;
}
return FALSE;
}
/**
* @return FileBackupService
*/
public function getBackupObj() {
return $this->backupObj;
}
/**
* @param FileBackupService $backupObj
*/
public function setBackupObj($backupObj) {
$this->backupObj = $backupObj;
}
}
\ No newline at end of file
......@@ -32,19 +32,13 @@ use SGalinski\Lfeditor\Utility\Functions;
use SGalinski\Lfeditor\Utility\SgLib;
use SGalinski\Lfeditor\Utility\Typo3Lib;
use TYPO3\CMS\Core\Localization\Locales;
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
class MainService implements SingletonInterface {
class ConfigurationService extends AbstractService {
//TODO: rename to ConfigurationService.
/**
* @inject
* @var \TYPO3\CMS\Extbase\Object\ObjectManager
*/
protected $objectManager = NULL;
/**
* @var array extension configuration
* @see prepareConfig()
......@@ -105,7 +99,7 @@ class MainService implements SingletonInterface {
) . '/';
// files
$this->extConfig['pathCSS'] = 'tx_lfeditor_mod1.css';
$this->extConfig['pathCSS'] = 'Resources/Public/StyleSheets/Lfeditor.css';
$this->extConfig['pathTinyMCEConfig'] = PATH_site .
ExtensionManagementUtility::siteRelPath('lfeditor') . 'Resources/Public/Scripts/TinyMCEConfig.js';
......
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<T3locallang>
<meta type="array">
<description>FileRef: EXT:lfeditor/mod1/locallang.xml&lt;br /&gt;&lt;br /&gt;Special Thanks:&lt;br /&gt;Peter Klein --&gt; danish translation&lt;br /&gt;Tapio Markula --&gt; finnish translation</description>
<description>FileRef: EXT:lfeditor/mod1/locallang.xml&lt;br /&gt;ttt&lt;br /&gt;Special Thanks:&lt;br /&gt;Peter Klein --&gt; danish translation&lt;br /&gt;Tapio Markula --&gt; finnish translation</description>
Please register or sign in to reply
<type>module</type>
<generator>LFEditor</generator>
<authorName>Stefan Galinski</authorName>
<authorEmail>stefan.galinski@gmail.com</authorEmail>
<authorName>Stefan Galinskittt</authorName>
<authorEmail>stefan.galinski@gmail.comTTt</authorEmail>
</meta>
<data type="array">
<languageKey index="default" type="array">
......
{namespace lfe=SGalinski\Lfeditor\ViewHelpers}
<lfe:addJavaScriptFile javaScriptFile="{f:uri.resource(path: 'Scripts/FormUtility.js')}" />
<lfe:addCssFile cssFile="{f:uri.resource(path: 'StyleSheets/Lfeditor.css')}" />
<f:be.container enableClickMenu="FALSE" loadPrototype="FALSE" loadExtJs="FALSE">
......@@ -33,7 +34,6 @@
<div id="typo3-docbody">
<div id="typo3-inner-docbody">
<f:form id="mainMenuForm" action="{mainMenuSelection}ChangeSelection">
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<f:flashMessages renderMode="div" />
<f:translate key="select.extension" />
<br>
......@@ -42,13 +42,10 @@
options="{extensionOptions}"
additionalAttributes="{onchange: 'submitForm(\'mainMenuForm\')'}"
/>
<br><br>
<br>
<f:render section="selectItems" />
</f:form>
<br><br>
<f:render section="main" />
</div>
......@@ -58,6 +55,7 @@
<f:comment>
<f:debug title="All available variables">{_all}</f:debug>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<div>
This is Default layout. <br>
<f:form id="mainMenuForm" action="mainMenuSelect">
......
......@@ -4,4 +4,5 @@
value="{languageFileSelection}"
options="{languageFileOptions}"
additionalAttributes="{onchange: 'submitForm(\'mainMenuForm\')'}"
/>
\ No newline at end of file
/>
<br>
\ No newline at end of file
......@@ -5,3 +5,4 @@
options="{referenceLanguageOptions}"
additionalAttributes="{onchange: 'submitForm(\'mainMenuForm\')'}"
/>
<br>
\ No newline at end of file
<f:layout name="Default" />
<f:section name="selectItems">
This is General page. Select items section.
<br>
<f:render partial="SelectLanguageFile" arguments="{_all}" />
<br>
<f:render partial="SelectReferenceLanguage" arguments="{_all}" />
<br>
<f:translate key="function.general.general" />
<br>
</f:section>
<f:section name="main">
This is General page. Main section.
<f:translate key="function.general.general" />
<br><br>
<div>
<table>
<tr>
<td>
<f:translate key="lang.shortcut" />
</td>
<td>
<f:translate key="lang.state" />
</td>
<td>
<f:translate key="ext.type" />
</td>
<td>
<f:translate key="lang.origin" />
</td>
</tr>
<table id="tx-lfeditor-table">
<thead>
<tr>
<th class="bgColor5">