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

[!!!][TASK] Allow to disable siteHash check by setting query.allowedSites to * #929

Merged

Conversation

timohund
Copy link
Contributor

@timohund timohund commented Jan 30, 2017

This PR changes the behaviour of query.allowedSites; the behavior * has been changed:

  • Before: * was the same as __all, which means all sites in the system
  • After: __all is still handled as __all sites in the system, but * now means every site (same as no check at all)

Implementation Details

During the implementation the following things have been done

  • Move SiteHash related logic from Util* to SiteHashService* and make them non static (See: http://wiki.c2.com/?AbuseOfUtilityClasses)
  • Mark SiteHash related method in Util deprecated and announce removal
  • Added Tests for Query and SiteHashService modifications
  • If variants should be used across multiple instances the variantId needs to be unique by system (not by site!). As of now the variantId only contains (type/uid), to have a unique variantId across multiple systems, a system hash was added.

Impact & Migration

  • If you use * for query.allowedSites please use __all now unless you want to disable the siteHash check
  • If you use variants, it is recommended to reindex your pages, since the hash was changed.

Fixes: #862

@timohund timohund added this to the 6.1 - Get ready for 8 LTS milestone Jan 30, 2017
@timohund timohund changed the title [!!!][TASK] Allow to disable siteHash chech by setting query.allowedSites to * [!!!][TASK] Allow to disable siteHash check by setting query.allowedSites to * Jan 30, 2017
@timohund timohund force-pushed the task/master/862-allow-to-disable-siteHash branch from ab09be1 to 4bbdd8e Compare January 30, 2017 16:22
*/
public function getAllowedSitesForPageIdAndAllowedSitesConfiguration($pageId, $allowedSitesConfiguration)
{
if ($allowedSitesConfiguration == '__all') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use strict ===

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

return $siteHashes[$domain];
}

$siteHashes[$domain] = sha1($domain . $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] . 'tx_solr');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just moved, the hash should be the same as before

/***************************************************************
* Copyright notice
*
* (c) 2010-2017 Timo Hund <timo.hund@dkd.de
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If new file 2017- and missing >

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

/***************************************************************
* Copyright notice
*
* (c) 2010-2017 Timo Hund <timo.hund@dkd.de
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If new file 2017 and agin missing >

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}

/**
* Retrieves the domain of the site that belongs to the passed pageId and replaces ther markers __solr_current_site
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

their?

*
* @param $pageId
* @param $allowedSitesConfiguration
* @return mixed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it mixed or string as return type?

* @param integer $uid
* @return string
*/
protected function applyHook($variantId, $systemHash, $type, $uid)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be better to use the new Signal concept in TYPO3? - I think hooks are only kept for compatibility

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

signals don't work for every scenario. If you want to change data, you still need hooks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think signals and slots are more like "events" and the intension is normally a one way direction. It is possible to return data, but only by passing a variable by reference (what is not optimal i would say). I think with hooks you can directly return a value, what is needed in this case (Add btw. in the changes of the core also new hooks are added).

*/
protected function getSystemHash()
{
$siteName = isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']) ? $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] : 'none';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im not sure TYPO3 works with this $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] - but I think I would throw an exception instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll propose to throw an exception when sitename is not set.

Copy link
Collaborator

@irnnr irnnr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, pending minor changes.

/***************************************************************
* Copyright notice
*
* (c) 2016 Timo Hund <timo.hund@dkd.de>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$year++

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] = 'testKey';

$service = new SiteHashService();
$hash1 = $service->getSiteHashForDomain('www.test.de');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use www.example.com for such use-cases. test.de is Stiftung Warentest.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@timohund timohund force-pushed the task/master/862-allow-to-disable-siteHash branch 2 times, most recently from 9a6c08b to c1e535b Compare January 31, 2017 09:57
…ites to *

This PR changes the behaviour of query.allowedSites the previos setting * behaviour was changed:

* Before: * was the same as __all, which means all sites in the system
* After: __all is still handled as __all sites in the system, but * now means every site (same as no check at all)

Migration: When you are using * for query.allowedSites change the setting to __all.

During the implementation the following things have been done

* Move SiteHash related logic from Util* to SiteHashService* and make them non static (See: http://wiki.c2.com/?AbuseOfUtilityClasses)
* Mark SiteHash related method in Util deprecated and announce removal
* Added Tests for Query and SiteHashService modifications
* When variants should be used accross multiple instances the variantId needs to be unique by system (not by site!). By now the variantId only contains (type/uid), to have a unique variantId accros multiple systems, a
system hash was added.

Impact:

* If you use * for query.allowedSites please use __all now unless you want to disable the siteHash check
* If you use variants, it is recommended to reindex your pages, since the hash was changed.

Fixes: TYPO3-Solr#862
@timohund timohund force-pushed the task/master/862-allow-to-disable-siteHash branch from c1e535b to 2d2c141 Compare January 31, 2017 10:27
@timohund timohund merged commit 034cdd6 into TYPO3-Solr:master Jan 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants