Typo3 9 - clear cache for a page id - typo3

For Typo3 8 following approach worked:
$tce = GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
$tce->clear_cacheCmd($pid);
Using this in Typo3 9 causes this error:
Call to a member function getTSConfig() on null
in E:\wwwroot_T9LTS\typo3\sysext\core\Classes\DataHandling\DataHandler.php line 8971
What is the best approach to clear cache for a page id in Typo3 9?
Update
got it to work using CacheManager:
$cacheManager = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class);
$cacheManager->flushCachesInGroupByTags('pages', [ 'pageId_'.$pid ]);

You probably run into problems using the DataHandler to clear the cache when not logged in to the backend. In Extbase context you may use:
$cacheManager = $this->objectManager->get(\TYPO3\CMS\Extbase\Service\CacheService::class);
$cacheManager->clearPageCache([1,2,3]);

You will have to initialize the class by calling the start() method:
$tce = GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
$tce->start([], []);
$tce->clear_cacheCmd($pid);
See the documentation for details.

Related

RealURL with GET parameters

We have developed a typo3 plug in that searches for trucks. For SEO reasons, we are trying to use the realURL plug in to make the URLs friendlier to use.
On the front page we have several call to actions that link to the search page with certain search parameters. An example is bellow:
/search-results/?tx_fds_searchresults[type_name]=Trailer
This link works as expected. On the results page is a link to the listings page with more details. An example is bellow:
/listing/?tx_fds_listing[id]=119870
This link is not working. tx_fds_listing[id] is not being populated in the arguments passed to the plug in controller.
At first we thought it might be a config issue but again, it isn't present on other pages.
The ID is not a database object and may be a text string instead.
Edit:
I should add that it works fine with RealURL turned off.
We get the id as $id = $this->request->getArgument('id');
Edit 2:
Here is the error message from the logs.
[ALERT] request="28233e225150a" component="TYPO3.CMS.Frontend.ContentObject.Exception.ProductionExceptionHandler": Oops, an error occurred! Code: 201512141630381db91bba - {"exception":"exception 'TYPO3\\CMS\\Extbase\\Mvc\\Exception\\NoSuchArgumentException' with message 'An argument \"id\" does not exist for this request.'
I also tried renaming the variable to name, but that didn't work either.
I have a solution that solves the root cause of the problem, if not the specific issue.
So I had to add additional mapping to the realurl_conf.php file. For example to get the listing id:
$config['domain.com']['postVarSets'][3]['stock'] = array(array('GETvar' => 'tx_fds_listing[id]'));
This makes the effective URL:
/listing/stock/119870
This was the intended usage for the plugin, so this is a good result. I also added configuration for ajax and pdfs. This required modification to the typoscript that was not obvious.
PDF TS:
pdf = PAGE
pdf {
typeNum = 300
10 = USER_INT
10 {
userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run
#vendorName = TYPO3
extensionName = Fds
pluginName = Listing
#controller = FDS
controller = Tx_Fds_Controller_FDSController
#action = listingPdf
switchableControllerActions.FDS.1 = listingPdf
}
config {
disableAllHeaderCode = 1
additionalHeaders = Content-type:application/pdf
xhtml_cleaning = 0
admPanel = 0
}
}
PDF RealURL Config:
$config['domain.com']['postVarSets'][3]['pdf'] = array('type' => 'single', 'keyValues' => array ('type' => 300));
PDF effective URL:
/listing/pdf/stock/119870

MongoDB & FosUserBundle - lack of columns

When I load data using data-fixtures to my mongoDB
private function loadAdminUser()
{
$userManager = $this->container->get('fos_user.user_manager');
// Create our user and set details
$user = $userManager->createUser();
$user->setUsername('username');
$user->setEmail('email#domain.com');
$user->setPlainPassword('password');
//$user->setPassword('3NCRYPT3D-V3R51ON');
$user->setEnabled(true);
$user->setRoles(array('ROLE_ADMIN'));
}
or when I use console/terminal for it
php app/console fos:user:create adminuser --super-admin
Everyhing is ok (no errors while updating).
But when I try to get that data from mongo it only returns me 4 columns:
while in FOSUserBudnle there is about 15(?) default columns... What's wrong?
I've done it. The problem was because Sonata was extending from use Sonata\UserBundle\Document\BaseUser as BaseUser not from use FOS\UserBundle\Document\User as BaseUser. I have changed it in Application\Sonata\UserBundle\Document and now it is ok

Joomla 3.3: Get data from column 'attribs' in the table 'content'

I'm using the Aixeena Easy CCK-plugin in my Joomla 3.3-website. It's a plugin that allows me to add custom fields in my Article Edit-page. The content I fill out there (should) show up on my website. The plugin stores his information in the #_content table in the attribs column.
On their website, Aixeena says that I have to use the following code to make the filled out text visible on my website:
$attrb = json_decode($this->item->attribs);
echo $attrb->fieldname;
This code drops the following error:
Notice: Undefined property: JDocumentHTML::$item in /Applications/MAMP/htdocs/buutpot/templates/buutpot.nl-standaardtemplate/index.php on line 123
Notice: Trying to get property of non-object in /Applications/MAMP/htdocs/buutpot/templates/buutpot.nl-standaardtemplate/index.php on line 123
Fatal error: Call to a member function get() on a non-object in /Applications/MAMP/htdocs/buutpot/templates/buutpot.nl-standaardtemplate/index.php on line 124
I think it is written for an older version of Joomla. Then I searched around and found this code:
$params = $this->item->params;
echo $params->get('fieldname');
When I use this code on my site, it gives me the following error's:
Notice: Undefined property: JDocumentHTML::$item in /Applications/MAMP/htdocs/buutpot/templates/buutpot.nl-standaardtemplate/index.php on line 123
Notice: Trying to get property of non-object in /Applications/MAMP/htdocs/buutpot/templates/buutpot.nl-standaardtemplate/index.php on line 123
Notice: Trying to get property of non-object in /Applications/MAMP/htdocs/buutpot/templates/buutpot.nl-standaardtemplate/index.php on line 124
That's without a fatal error. I'm not sure why it is without.
Could anybody help me out getting the right code to get my variable out of the table? Thanks in advance!
EDIT 1: Link to the plugin: http://www.aixeena.org/aixeena-lab/aixeena-easy-cck
EDIT 2: Edited my question in reply on the comment of Elin.
So like the notices say, the problem is that $this->item does not exist. You need to figure out what the actual name of the object is and use that rather than $this->item. You will probably do that by looking in the layout of whereever it is that you are trying to display. Can you please check your template to see if it has a layout override for the article view (assuming that is the view you are trying to access the form from)?
I used this code to do a query on the database:
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('attribs');
$query->from($db->quoteName('#__content'));
$query->where($db->quoteName('id')." = ".JRequest::getInt('id'));
$db->setQuery($query);
$attribs = $db->loadResult();
$attribs = json_decode($attribs, 'true');
$firstattr = $attribs['firstattr'];
$secondattr = $attribs['secondattr'];
$thirdattr = $attribs['thirdattr'];
$fourthattr = $attribs['fourthattr'];
But I'm sure this can be done simpler.
$attribs = new JRegistry($article->attribs);
echo $fieldname = $attribs['fieldname'];
For example, I use this code in on ContentPrepare like this
function onContentPrepare($context, &$article, &$params, $page) {
$attribs = new JRegistry($article->attribs);
//url is my custom field for the content
$url = $attribs['url'];
......

How do I bootstrap a plugin on TYPO3 CMS 6.0 with extbase?

I'm trying to use an extbase plugin through typoscript on TYPO3 CMS 6.0. I used the following code, that I found repeated all over the web:
10 = USER
10 {
userFunc = tx_extbase_core_bootstrap->run
pluginName = Sermons
extensionName = VmfdsSermons
switchableControllerActions {
Sermon {
1 = byLatestSeries
2 = list
3 = show
}
}
However, this just gives me the following error:
#1289386765: Could not analyse class:Tx_VmfdsSermons_Controller_SermonController maybe not loaded or no autoloader?
It seems to me as if tx_extbase_core_bootstrap->run is not using namespaces yet, thus trying to load a class called Tx_VmfdsSermons_Controller_SermonController when it should have called \TYPO3\VmfdsSermons\Controller\SermonController. Is there a way around this?
You're searching for the property vendorName. So in your case it should be:
10 = USER
10 {
userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run
pluginName = Sermons
extensionName = VmfdsSermons
vendorName = TYPO3
[...]
I also used the vendor namespace within ext_localconf.php:
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'<Vendor>.' . $_EXTKEY,
[...]
I found the answer by using the debugger. I started at \TYPO3\CMS\Extbase\Mvc\Dispatcher::resolveController() and jumped into TYPO3\CMS\Extbase\Mvc\Request::getControllerObjectName(). There is a member controllerVendorName, so I searched in Extbase for the setter of \TYPO3\CMS\Extbase\Mvc\Request::setControllerVendorName(), precisely just for setControllerVendorName, and got a match in \TYPO3\CMS\Extbase\Mvc\Web\RequestBuilder::build(), where is a member called vendorName, and just in the method above \TYPO3\CMS\Extbase\Mvc\Web\RequestBuilder::loadDefaultValues(), is the answer!
Calling tx_extbase_core_bootstrap should no longer be used as it is deprecated in ver. 6.0 and will be removed in 7.0
You can try different. Developers should now handle everything with namespaces ...
You can use this:
# bootstrap aufrufen -> run from extbase
userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run

Call TYPO3 plugin from other plugin's body

I need to call typo3 plugin from other plugin's body and pass its result to template. This is pseudo-code that describes what I want to achieve doing this:
$data['###SOME_VARIABLE###'] = $someOtherPlugin->main();
$this->cObj->substituteMarkerArray($someTemplate, $data);
Is it possible?
Thanks!
It doenst work if you use the whole pi construct, e.g. for links, marker function etc, and the TSFE Data can be corrupted.
Dmitry said:
http://lists.typo3.org/pipermail/typo3-english/2008-August/052259.html
$cObjType = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_rgsmoothgallery_pi1'];
$conf = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_rgsmoothgallery_pi1.'];
$cObj = t3lib_div::makeInstance('tslib_cObj');
$cObj->start(array(), '_NO_TABLE');
$conf['val'] = 1;
$content = $cObj->cObjGetSingle($cObjType, $conf); //calling the main method
You should use t3lib_div:makeInstance method.
There is a working example from TYPO3's "powermail" extension.
function getGeo() {
// use geo ip if loaded
if (t3lib_extMgm::isLoaded('geoip')) {
require_once( t3lib_extMgm::extPath('geoip').'/pi1/class.tx_geoip_pi1.php');
$this->media = t3lib_div::makeInstance('tx_geoip_pi1');
if ($this->conf['geoip.']['file']) { // only if file for geoip is set
$this->media->init($this->conf['geoip.']['file']); // Initialize the geoip Ext
$this->GEOinfos = $this->media->getGeoIP($this->ipOverride ? $this->ipOverride : t3lib_div::getIndpEnv('REMOTE_ADDR')); // get all the infos of current user ip
}
}
}
The answer of #mitchiru is nice and basically correct.
If you have created your outer extension with Kickstarter and you are using pi_base then there is already an instance of tslib_cObj and the whole construct becomes simpler:
// get type of inner extension, eg. USER or USER_INT
$cObjType = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_innerextension_pi1'];
// get configuration array of inner extension
$cObjConf = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_innerextension_pi1.'];
// add own parameters to configuration array if needed - otherwise skip this line
$cObjConf['myparam'] = 'myvalue';
// call main method of inner extension, using cObj of outer extension
$content = $this->cObj->cObjGetSingle($cObjType, $cObjConf);
Firstly, you have to include your plugin class, before using, or outside your class:
include_once(t3lib_extMgm::extPath('myext').'pi1/class.tx_myext_pi1.php');
Secondly in your code (in the main as example)
$res = tx_myext_pi1::myMethod();
This will work for sure (I've checked this): http://lists.typo3.org/pipermail/typo3-english/2008-August/052259.html.
Probably Fedir's answer is correct too but I didn't have a chance to try it.
Cheers!