Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Alias per page #576

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Classes/Controller/AliasesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ protected function doesAliasExistsForAnotherRecord($aliasValue) {
$query->equals('valueAlias', $aliasValue),
$query->equals('tablename', $alias->getTablename()),
$query->equals('lang', $alias->getLang()),
$query->equals('pageId', $alias->getPageId()),
$query->logicalNot($query->equals('uid', (int)$alias->getUid()))
)));

Expand Down Expand Up @@ -258,6 +259,7 @@ protected function processSelectedAlias($selectedAlias) {
$query->matching(count($conditons) > 1 ? $query->logicalAnd($conditons) : reset($conditons));
$query->setOrderings(array(
'valueId' => QueryInterface::ORDER_ASCENDING,
'pageId' => QueryInterface::ORDER_ASCENDING,
'lang' => QueryInterface::ORDER_ASCENDING,
));

Expand Down
7 changes: 4 additions & 3 deletions Classes/Decoder/UrlDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,14 +282,15 @@ protected function checkMissingSlash() {
*
* @param array $configuration
* @param string $value
* @param int $pageId
* @return int|string
*/
protected function convertAliasToId(array $configuration, $value) {
protected function convertAliasToId(array $configuration, $value, $pageId) {
$result = (string)$value;

// First, test if there is an entry in cache for the alias
if ($configuration['useUniqueCache']) {
$cachedId = $this->getFromAliasCacheByAliasValue($configuration, $value);
$cachedId = $this->getFromAliasCacheByAliasValue($configuration, $value, $pageId);
if (MathUtility::canBeInterpretedAsInteger($cachedId)) {
$result = (int)$cachedId;
}
Expand Down Expand Up @@ -757,7 +758,7 @@ protected function decodeUrlParameterBlockUsingLookupTable(array $configuration,
$result = FALSE;

if (isset($configuration['lookUpTable'])) {
$value = $this->convertAliasToId($configuration['lookUpTable'], $getVarValue);
$value = $this->convertAliasToId($configuration['lookUpTable'], $getVarValue, $requestVariables['id']);
if (!MathUtility::canBeInterpretedAsInteger($value) && $value === $getVarValue) {
if ($configuration['lookUpTable']['enable404forInvalidAlias']) {
$this->throw404('Could not map alias "' . $value . '" to an id.');
Expand Down
17 changes: 17 additions & 0 deletions Classes/Domain/Model/Alias.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ class Alias extends AbstractEntity {
/** @var int */
protected $valueId;

/** @var int */
protected $pageId;

/**
* @return int
*/
Expand Down Expand Up @@ -146,6 +149,20 @@ public function setValueId($valueId) {
$this->valueId = $valueId;
}

/**
* @return int
*/
public function getPageId() {
return $this->pageId;
}

/**
* @param int $pageId
*/
public function setPageId($pageId) {
$this->pageId = $pageId;
}

/**
* @return string
*/
Expand Down
4 changes: 3 additions & 1 deletion Classes/EncodeDecoderBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,16 @@ abstract protected function initializeConfiguration();
*
* @param array $configuration
* @param string $aliasValue
* @param int $pageId
* @return int ID integer. If none is found: false
*/
protected function getFromAliasCacheByAliasValue(array $configuration, $aliasValue) {
protected function getFromAliasCacheByAliasValue(array $configuration, $aliasValue, $pageId) {
$row = $this->databaseConnection->exec_SELECTgetSingleRow('value_id', 'tx_realurl_uniqalias',
'value_alias=' . $this->databaseConnection->fullQuoteStr($aliasValue, 'tx_realurl_uniqalias') .
' AND field_alias=' . $this->databaseConnection->fullQuoteStr($configuration['alias_field'], 'tx_realurl_uniqalias') .
' AND field_id=' . $this->databaseConnection->fullQuoteStr($configuration['id_field'], 'tx_realurl_uniqalias') .
' AND tablename=' . $this->databaseConnection->fullQuoteStr($configuration['table'], 'tx_realurl_uniqalias') .
(intval($pageId) > 0 ? ' AND page_id=' . intval($pageId) : '') .
' AND (expire=0 OR expire>' . time() . ')');

return (is_array($row) ? (int)$row['value_id'] : false);
Expand Down
7 changes: 5 additions & 2 deletions Classes/Encoder/UrlEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ protected function createUniqueAlias(array $configuration, $newAliasValue, $idVa
$testNewAliasValue = $newAliasValue;
while ($counter < $maxTry) {
// If the test-alias did NOT exist, it must be unique and we break out
$foundId = $this->getFromAliasCacheByAliasValue($configuration, $testNewAliasValue);
$foundId = $this->getFromAliasCacheByAliasValue($configuration, $testNewAliasValue, $this->urlParameters['id']);
if (!$foundId || $foundId == $idValue) {
$uniqueAlias = $testNewAliasValue;
break;
Expand Down Expand Up @@ -1080,6 +1080,7 @@ protected function getFromAliasCache(array $configuration, $getVarValue, $langua
' AND field_id=' . $this->databaseConnection->fullQuoteStr($configuration['id_field'], 'tx_realurl_uniqalias') .
' AND tablename=' . $this->databaseConnection->fullQuoteStr($configuration['table'], 'tx_realurl_uniqalias') .
' AND lang=' . intval($languageUid) .
' AND page_id=' . intval($this->urlParameters['id']) .
($onlyThisAlias ? ' AND value_alias=' . $this->databaseConnection->fullQuoteStr($onlyThisAlias, 'tx_realurl_uniqalias') : ' AND expire=0'),
'', 'expire'
);
Expand Down Expand Up @@ -1467,6 +1468,7 @@ protected function storeInAliasCache(array $configuration, $newAliasValue, $idVa
AND field_id=' . $this->databaseConnection->fullQuoteStr($configuration['id_field'], 'tx_realurl_uniqalias') . '
AND tablename=' . $this->databaseConnection->fullQuoteStr($configuration['table'], 'tx_realurl_uniqalias') . '
AND lang=' . intval($languageUid) . '
AND page_id=' . intval($this->urlParameters['id']) . '
AND expire=0', array('expire' => time() + 24 * 3600 * ($configuration['expireDays'] ? $configuration['expireDays'] : 60)));

// Store new alias
Expand All @@ -1476,7 +1478,8 @@ protected function storeInAliasCache(array $configuration, $newAliasValue, $idVa
'field_id' => $configuration['id_field'],
'value_alias' => $uniqueAlias,
'value_id' => $idValue,
'lang' => $languageUid
'lang' => $languageUid,
'page_id' => $this->urlParameters['id']
);
$this->databaseConnection->exec_INSERTquery('tx_realurl_uniqalias', $insertArray);
$aliasRecordId = $this->databaseConnection->sql_insert_id();
Expand Down
7 changes: 7 additions & 0 deletions Configuration/TCA/tx_realurl_uniqalias.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@
'eval' => 'required',
)
),
'page_id' => array(
'label' => 'LLL:EXT:realurl/Resources/Private/Language/locallang_db.xlf:tx_realurl_uniqalias.page_id',
'config' => array(
'type' => 'input',
'eval' => 'required',
)
),
),
'types' => array(
'types' => array(
Expand Down
6 changes: 6 additions & 0 deletions Resources/Private/Language/locallang.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
<trans-unit id="module.aliases.edit.alias_info.field_value">
<source>Field value:</source>
</trans-unit>
<trans-unit id="module.aliases.edit.alias_info.page_id">
<source>Page id:</source>
</trans-unit>
<trans-unit id="module.aliases.edit.saved">
<source>Alias successfully updated.</source>
</trans-unit>
Expand Down Expand Up @@ -111,6 +114,9 @@
<trans-unit id="module.tableHeader.language">
<source>Language</source>
</trans-unit>
<trans-unit id="module.tableHeader.page_id">
<source>Page id</source>
</trans-unit>
<trans-unit id="module.tableHeader.expire">
<source>Expires</source>
</trans-unit>
Expand Down
3 changes: 3 additions & 0 deletions Resources/Private/Language/locallang_db.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@
<trans-unit id="tx_realurl_uniqalias.field_id">
<source>Field id:</source>
</trans-unit>
<trans-unit id="tx_realurl_uniqalias.page_id">
<source>Page id:</source>
</trans-unit>
<trans-unit id="tx_realurl_urldata">
<source>RealURL URL Data</source>
</trans-unit>
Expand Down
6 changes: 6 additions & 0 deletions Resources/Private/Templates/Aliases/Edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ <h3><f:translate key="LLL:EXT:realurl/Resources/Private/Language/locallang.xlf:m
<p>{alias.recordFieldValue}</p>
</div>
</div>
<div class="form-group">
<label class="col-sm-2"><f:translate key="LLL:EXT:realurl/Resources/Private/Language/locallang.xlf:module.aliases.edit.alias_info.page_id"/></label>
<div class="col-sm-10">
<p>{alias.pageId}</p>
</div>
</div>
<div class="form-group">
<label class="col-sm-2" for="aliasValue"><f:translate key="LLL:EXT:realurl/Resources/Private/Language/locallang.xlf:module.aliases.edit.alias_value"/></label>
<div class="col-sm-10">
Expand Down
2 changes: 2 additions & 0 deletions Resources/Private/Templates/Aliases/Index.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ <h3><f:translate key="LLL:EXT:realurl/Resources/Private/Language/locallang.xlf:m
<th><f:translate key="module.tableHeader.alias"/></th>
<th class="col-sm-1"><f:translate key="module.tableHeader.id"/></th>
<th class="col-sm-2"><f:translate key="module.tableHeader.language"/></th>
<th class="col-sm-2"><f:translate key="module.tableHeader.page_id"/></th>
<th class="col-sm-2"><f:translate key="module.tableHeader.expire"/></th>
</tr>
<f:for each="{aliases}" as="alias">
Expand Down Expand Up @@ -107,6 +108,7 @@ <h3><f:translate key="LLL:EXT:realurl/Resources/Private/Language/locallang.xlf:m
<td>{alias.valueAlias}</td>
<td class="col-sm-1">{alias.valueId}</td>
<td class="col-sm-2">{d:languageFromId(language: alias.lang)}</td>
<td class="col-sm-2">{alias.pageId}</td>
<td class="col-sm-2">
<f:if condition="{alias.expire}">
<f:then>
Expand Down
1 change: 1 addition & 0 deletions ext_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ CREATE TABLE tx_realurl_uniqalias (
value_id int(11) DEFAULT '0' NOT NULL,
lang int(11) DEFAULT '0' NOT NULL,
expire int(11) DEFAULT '0' NOT NULL,
page_id INT(11) DEFAULT '0' NOT NULL,

PRIMARY KEY (uid),
KEY parent (pid),
Expand Down