Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
sg_routes
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
TYPO3
sg_routes
Commits
938deaa7
Commit
938deaa7
authored
Mar 21, 2019
by
Paul Ilea
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[FEATURE] Add unique source url check for BE Module editing
parent
cb1fe688
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
115 additions
and
2 deletions
+115
-2
Classes/Domain/Repository/RouteRepository.php
Classes/Domain/Repository/RouteRepository.php
+13
-2
Classes/Hook/RouteDataHandlerHook.php
Classes/Hook/RouteDataHandlerHook.php
+92
-0
Resources/Private/Language/de.locallang_db.xlf
Resources/Private/Language/de.locallang_db.xlf
+4
-0
Resources/Private/Language/locallang_db.xlf
Resources/Private/Language/locallang_db.xlf
+3
-0
ext_localconf.php
ext_localconf.php
+3
-0
No files found.
Classes/Domain/Repository/RouteRepository.php
View file @
938deaa7
...
...
@@ -131,14 +131,25 @@ class RouteRepository extends Repository {
*
* @param int $pageUid
* @param string $sourceUrl
* @param array $excludeUids
* @return bool
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
*/
public
function
sourceUrlRouteExists
(
$pageUid
,
$sourceUrl
)
:
bool
{
public
function
sourceUrlRouteExists
(
$pageUid
,
$sourceUrl
,
array
$excludeUids
=
[]
)
:
bool
{
$query
=
$this
->
createQuery
();
$querySettings
=
$query
->
getQuerySettings
();
$querySettings
->
setStoragePageIds
([
$pageUid
]);
$query
->
setQuerySettings
(
$querySettings
);
$query
->
matching
(
$query
->
equals
(
'source_url'
,
\trim
(
$sourceUrl
)));
$constraints
=
[
$query
->
equals
(
'source_url'
,
\trim
(
$sourceUrl
))
];
if
(
\count
(
$excludeUids
))
{
$constraints
[]
=
$query
->
logicalNot
(
$query
->
in
(
'uid'
,
$excludeUids
));
}
$query
->
matching
(
$query
->
logicalAnd
(
$constraints
));
$query
->
setLimit
(
1
);
return
\count
(
$query
->
execute
(
TRUE
))
>
0
;
...
...
Classes/Hook/RouteDataHandlerHook.php
0 → 100644
View file @
938deaa7
<?php
namespace
SGalinski\SgRoutes\Hook
;
use
SGalinski\SgRoutes\Domain\Repository\RouteRepository
;
use
TYPO3\CMS\Backend\Utility\BackendUtility
;
use
TYPO3\CMS\Core\Messaging\FlashMessage
;
use
TYPO3\CMS\Core\Messaging\FlashMessageService
;
use
TYPO3\CMS\Core\Utility\GeneralUtility
;
use
TYPO3\CMS\Extbase\Object\ObjectManager
;
use
TYPO3\CMS\Extbase\Utility\LocalizationUtility
;
/***************************************************************
* Copyright notice
*
* (c) sgalinski Internet Services (https://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!
***************************************************************/
class
RouteDataHandlerHook
{
/**
* Called after a record was edited or added.
*
* @param string $status DataHandler operation status, either 'new' or 'update'
* @param string $table The DB table the operation was carried out on
* @param mixed $id The record's uid for update records, a string to look the record's uid up after it has been created
* @param array $fieldArray Array of changed fields and their new values
* @throws \TYPO3\CMS\Core\Exception
*/
public
function
processDatamap_postProcessFieldArray
(
string
$status
,
string
$table
,
$id
,
array
&
$fieldArray
)
{
if
(
$table
!==
'tx_sgroutes_domain_model_route'
)
{
return
;
}
$id
=
(
int
)
$id
;
$sourceUrl
=
''
;
if
(
isset
(
$fieldArray
[
'source_url'
]))
{
$sourceUrl
=
\trim
(
$fieldArray
[
'source_url'
]);
}
if
(
$status
===
'new'
||
isset
(
$fieldArray
[
'pid'
]))
{
$pid
=
(
int
)
$fieldArray
[
'pid'
];
}
else
{
$oldValues
=
BackendUtility
::
getRecord
(
$table
,
$id
,
'pid, source_url'
);
$pid
=
(
int
)
$oldValues
[
'pid'
];
if
(
$sourceUrl
===
''
)
{
$sourceUrl
=
\trim
(
$oldValues
[
'source_url'
]);
}
}
$objectManager
=
GeneralUtility
::
makeInstance
(
ObjectManager
::
class
);
$routeRepository
=
$objectManager
->
get
(
RouteRepository
::
class
);
$routeExistsForSourceUrl
=
$routeRepository
->
sourceUrlRouteExists
(
$pid
,
$sourceUrl
,
[
$id
]);
if
(
$routeExistsForSourceUrl
)
{
/** @var FlashMessage $message */
$message
=
GeneralUtility
::
makeInstance
(
FlashMessage
::
class
,
LocalizationUtility
::
translate
(
'LLL:EXT:sg_routes/Resources/Private/Language/locallang_db.xlf:error.invalidSourceUrl'
,
NULL
,
[
$sourceUrl
]
),
''
,
// header is optional
FlashMessage
::
ERROR
,
TRUE
// whether message should be stored in session
);
/** @var $flashMessageService FlashMessageService */
$flashMessageService
=
GeneralUtility
::
makeInstance
(
FlashMessageService
::
class
);
$flashMessageService
->
getMessageQueueByIdentifier
()
->
enqueue
(
$message
);
unset
(
$fieldArray
[
'source_url'
]);
}
}
}
Resources/Private/Language/de.locallang_db.xlf
View file @
938deaa7
...
...
@@ -9,6 +9,10 @@
<authorEmail>
fabian@sgalinski.de
</authorEmail>
</header>
<body>
<trans-unit
id=
"error.invalidSourceUrl"
>
<source>
The Source URL "%s" is already redirected by another record.
</source>
<target>
Die Quell-URL "%s" wird bereits von einer anderen Datensatz weitergeleitet.
</target>
</trans-unit>
<trans-unit
id=
"tx_sgroutes_domain_model_category"
approved=
"yes"
>
<source>
Category
</source>
<target>
Kategorie
</target>
...
...
Resources/Private/Language/locallang_db.xlf
View file @
938deaa7
...
...
@@ -9,6 +9,9 @@
<authorEmail>
fabian@sgalinski.de
</authorEmail>
</header>
<body>
<trans-unit
id=
"error.invalidSourceUrl"
>
<source>
The Source URL "%s" is already redirected by another record.
</source>
</trans-unit>
<trans-unit
id=
"tx_sgroutes_domain_model_category"
>
<source>
Category
</source>
</trans-unit>
...
...
ext_localconf.php
View file @
938deaa7
...
...
@@ -62,6 +62,9 @@ call_user_func(
$GLOBALS
[
'TYPO3_CONF_VARS'
][
'SC_OPTIONS'
][
't3lib/class.t3lib_tcemain.php'
][
'processDatamapClass'
][]
=
SGalinski\SgRoutes\Hook\PageDataHandlerHook
::
class
;
$GLOBALS
[
'TYPO3_CONF_VARS'
][
'SC_OPTIONS'
][
't3lib/class.t3lib_tcemain.php'
][
'processDatamapClass'
][]
=
SGalinski\SgRoutes\Hook\RouteDataHandlerHook
::
class
;
if
(
!
is_array
(
$GLOBALS
[
'TYPO3_CONF_VARS'
][
'SC_OPTIONS'
][
'cms/layout/db_layout.php'
][
'drawHeaderHook'
]))
{
$GLOBALS
[
'TYPO3_CONF_VARS'
][
'SC_OPTIONS'
][
'cms/layout/db_layout.php'
][
'drawHeaderHook'
]
=
[];
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment