Home

Author Archive

The new scheduler. What is it? When do I need it?

Sunday, March 14th, 2010 | Author: Benni

TYPO3 4.3 brought a lot of cool stuff with its release in November 2009. Last week, I made use of one of them for the first time: The scheduler.

Some time ago, Kasper introduced a way to access TYPO3 from the command line (CLI). This allowed us to use the command line, and thus OS-internal applications like “cron” to schedule TYPO3 tasks that were executed in a recurring pattern, or at a single particular point in the future. Kasper created this so-called “cli_dispatcher.sh” file (found in the typo3/ directory) that would delegate the executed task to extensions that were used as parameter. However, there were some drawbacks (every task needed its own BE user), and extensions like “direct_mail” still used their own CLI script. However, there was one extension developed by Christian Julle Jensen, called “gabriel” in TER, the “arch angel” that would serve as one global place to execute timed TYPO3 tasks, and every extension could hook in. However, “gabriel” wasn’t prominent enough to gain attraction so that it would be a standard for all the other extensions.
For TYPO3 4.3, Francois Suter, Ingo Renner and some others, refactored the “gabriel” extension, named it “scheduler” and integrated it into the TYPO3 Core. The new extension comes with a handy info page to see if the BE user was added, if the scheduler runs on time and shows which line to add to my crontab. Now, one can configure the scheduler through the TYPO3 Backend and doesn’t need to edit the crontab to modify the execution for every task. The crontab now only knows one entry.
/var/www/path/to/my/site/htdocs/typo3/cli_dispatch.phpsh scheduler

The dispatcher calls the scheduler, and the scheduler dispatches to the tasks that need to be run at the time of execution.

OK. cool thing, so how to set up a task?

There are three things you need to do in advance:

* Install the “scheduler” extension
* Create the CLI user (see the scheduler module “Setup check”, and click on the link to add the CLI user)
* Add the crontab to e.g. have the scheduler run every 5 minutes. Like this:

/5 * * * * /var/www/path/to/my/site/htdocs/typo3/cli_dispatch.phpsh scheduler

Please check before adding to the crontab, if the command executes correctly in your environment, maybe an additional php package (”php-cli”) is needed.

Alright, so everything is in place, but now you need to schedule the tasks, because right now the scheduler has nothing to execute. There are already two “dummy” task types, a “Scheduler Test Task” and a “Scheduler Sleep Task”, which both don’t do anything useful.

There are already a few extensions that use the scheduler as a common CLI task center. Direct Mail creates a new “task type” so the sending process of Newsletters is taken care of through the scheduler and configuring Direct Mail just got one step easier :-). Try it out.

OK. Let’s take it one step further: I will show you how to create your own scheduler task type. A common issue I have to face with quite often is that some data import needs to happen every night at 1am. As usual, I create a new, local extension for that. This extension needs to be configured in three places.

1) ext_localconf.php
The scheduler needs to know that there is a new task type, and needs to know where to delegate it to. For this, a new array is created.

$TYPO3_CONF_VARS['SC_OPTIONS']['scheduler']['tasks']['tx_benniext_scheduler_importtask'] = array(
‘extension’ => ‘benniext’,
‘title’ => ‘Bennis Importer Task’,
‘description’ => ‘Imports my specific data every night (or that is what I hope it does for me)’
);

Where the key of this associative array (tx_benniext_scheduler_importtask) is the class that is used fot the task.

2) The new PHP class, which I put in my extension directory and call it “class.tx_benniext_scheduler_importtask.php”. The file contains a class which subclasses the PHP scheduler task class and has a public function called “execute()”.

class tx_benniext_scheduler_importtask extends tx_scheduler_Task {

/**
* Function executed from the Scheduler.
*
* @return    bool
*/
public function execute() {
// state if the execution went well
return true;
}
}

3) ext_autoload.php
Of course, the new file above needs to be found, and the new autoloader that also comes with TYPO3 4.3, is taking care of it as well.

return array(
'tx_benniext_scheduler_importtask' => t3lib_extMgm::extPath('benniext', 'class.tx_benniext_scheduler_importtask.php'),
);

If you’re creating a new extension, don’t forget to have an ext_icon.gif and ext_emconf.php in your extension directory.

The new task type is in place, and we can add a specific task, namely to execute this import task every day at 1am. This is done through the scheduler module by clicking on the “add task” button. Select the new “Bennis Importer Task” and add that it should be executed every night at 1am and that there is an interval of 86400 (60secs * 60mins * 24hs = 1 day = 86400 secs) seconds entered. Save the new task, and that’s it! Enjoy!

By the way: The scheduler module shows you if your task has been executed correctly on the next day.

Thanks for everyone involved in this feature. It really is so easy to use and extend. Thank you. The only thing I found confusing is the difference between these different task types, and a specific task I can create, but now I know ;-).

Category: TYPO3 | 7 Comments

Long awaited - or: how to get IE8 compatibility in TYPO3

Monday, October 12th, 2009 | Author: Benni

Hey,

if anybody followed the latest evolvements in TYPO3, one of my promises was to blog more often. So here comes the first step:

One quick and tiny trick I used pretty often the last months was to add the following meta-tag to let Internet Explorer 8 behave like its predecessor, IE7. The Tag is <meta http-equiv=”X-UA-Compatible” content=”IE=EmulateIE7″ />. You only need to add this snippet to the head of your HTML page and then you don’t need to worry about your existing design to work in IE8. However, I found out that you need to put this tag right after the <head> Tag for IE8 to recognize this — and well, TYPO3 has no easy way to get HTML code above the classic TYPO3 head comment part, only below (with page.headerData…). That’s why I just put it in the <head> tag, and - there is fortunately something like “PAGE.headTag” since ages in TypoScript. Thus, I only need to put something like that in my TypoScript setup:

page.headTag = <head><meta http-equiv=”X-UA-Compatible” content=”IE=EmulateIE7″ />

and my website is looking nice in IE7 (as before) and IE8 (as IE7).

Category: TYPO3 | Leave a Comment

DAM: Hiding fields through TSconfig

Sunday, September 21st, 2008 | Author: Benni

Long time no see… yes, business is keeping me away from all the fun stuff. I’m currently working on cleaning up and then extending mm_forum, and of course the TYPO3 core.  Last week, I visited Jeff in Dallas and we had a good run digging into some serious XML issues with libxml2 and expat (See http://bugs.typo3.org/view.php?id=9359) and we also looked into over 20 patches floating around in the TYPO3 core list.

Yesterday I spent some time working on my seo_basics extension and on the last fixes for the upcoming DAM (Digital Asset Management) version 1.1 — a beast of an extension,  but good for adding metadata to uploaded files. While there was a huge movement in May and June, things kinds slowed down in the last months, and Ben pushed the whole thing a bit more. In any case, 1.1 will be a bugfix release (with a dependency on TYPO3 4.2.2 or later) marking the way for a glorious 1.2 (Release TBA ;-)). more…

Category: TYPO3 | 3 Comments

TypoLink: Tiny Helpers To Save The Day #1

Thursday, July 17th, 2008 | Author: Benni

I more and more enjoy the power of TypoScript. Every day, I learn something new. I will

Tip 1: You want to link to the same page, but with JS params etc,

lib.mytext = TEXT
lib.mytext.value = This is a link
lib.mytext.typolink.parameter = {TSFE:id},775 500x600 selflink
lib.mytext.typolink.parameter.insertData = 1

I had to use this idea when having a big site with a lot of microsites where the client is able to clone a microsite without needing to configure any IDs. The typolink.parameter = this,775.. did not work.

Basically, with this project, I had to make sure that no page IDs were hardcoded in TypoScript, so it was easy to create a new site inside TYPO3.

The following example renders a menu based on keywords (there was a requirement about the page titles) instead of a special = directory type of menu.

lib.rightnav = HMENU
lib.rightnav {
  special = keywords
  special {
    value = 1
    depth = 2
    setKeywords = Contact,Newsletter
    keywordsField = title
    entryLevel = 0
  }
  1 = TMENU
  1 {
    alternativeSortingField = sorting
    noBlur = 1
    NO.allWrap = <li>|</li>
    wrap = <ul class="rightcol_contact">|</ul>
  }
}

The next example shows a tt_news to link to the first subpage as the “single page”.

plugin.tt_news.singlePid.cObject = HMENU
plugin.tt_news.singlePid.cObject {
	special = directory
	special.value.data = TSFE:id
	maxItems = 1
	includeNotInMenu = 1
	1 = TMENU
	1 {
		NO.doNotLinkIt = 1
		NO.stdWrap.field = uid
	}
}

I know it’s not big magic and can be solved differently as well, but it just keeps me busy these days :)

Category: TYPO3 | 3 Comments

When switching from baseURL to absRefPrefix…

Tuesday, July 01st, 2008 | Author: Benni

My latest thing to do is switching my TYPO3 installations from baseURL to absRefPrefix. Ever since this awesome extension realURL was written, there was the need to define the URLs that should be relative to the TYPO3 main directory. Imagine having a TYPO3 installation running under a domain called www.b13.de. Without realURL your TYPO3 generated URLs looked like:

http://www.b13.de/index.php?id=25

Well, we all know that search engines don’t like it and visitors don’t find it as convenient as having a real URL, that looks like that

http://www.b13.de/en/about/downloads/
http://www.b13.de/en/products/saviour-v1/

Great! Let’s do this. RealURL does everything for you. Very simple and good (and bug-free — I love the latest version, thanks Dmitry!). However, if you’re on the downloads page and want to link to the products detail page, then the link will look like

http://www.b13.de/en/about/downloads/en/products/saviour-v1/

The reason is that realURL (or let’s say, your browser) does not know where the root of your installation is. realURL suggests using the <base href=”http://www.b13.de/”> tag to let the browser know that all relative links are relative not to the current page but to the specified base href. You can configure this in TypoScript with config.baseURL = http://www.b13.de/ and then there you go.

This all works fine — and if you have multiple domains, you just need to use TypoScript conditions, but this is all doable. However, in the recent past a few of my clients (NOTE: only the ones with 404 pages managed through TYPO3) ran into problems with strange floods of their log files with zillion 404 calls. The reason was that there are some bots that don’t interpret the baseURL tag, and then call the non-existent URLs (e.g. images), which redirect to the 404 which also includes the 404 path. Yes, quite annoying.

So, I was searching for an alternative. Dmitry posted some information on his blog about this error as well. The htaccess redirect he mentioned worked just fine, but I really wanted to avoid this in general, asking a simple question: “Can’t I just set a slash (/) in front of every URL and file reference of my generated HTML?”. This was something I actually wanted before I used this baseURL configuration option (yes, a long time ago). And, in fact, there was this option “config.absRefPrefix” lying around the whole time, and I never used it. As you can see there are so many things you find every time in TYPO3. With the absRefPrefix option I don’t even need to bother with the domains if I just use

config.absRefPrefix = /

or

config.absRefPrefix = /path/to/my/t3installation/

depending on the location of the TYPO3 mainsite directory. But it looked like it’s not that easy, because I ran into some issues (after switching 4 or 5 sites from baseURL to absRefPrefix).

  • You need to have the latest realURL version and set the “reapplyAbsRefPrefix = true” in your realURL configuration array to keep the prefix.
  • Linking between domains is not as smooth anymore as with the latest realURL and 4.2
  • If you have references to typo3conf/ext/, they won’t be prefixed. I ran into this by having: <link rel=”stylesheet” type=”text/css” href=”typo3conf/ext/rgmedialinks/res/mediabox.css” />. I noticed that this is a bug in the TYPO3 core, so I fixed it.
  • There are still some errors if you use custom extensions. You need to make sure that these work. I had trouble with mailforms and some custom scripts that alter the “img” tag, because the URL wasn’t typo3temp/ anymore but http://www.b13.de/typo3temp, so some default replacements didn’t work anymore. Nothing serious, but just something to keep in mind.
  • The latest issue that the Magic images I added during the baseURL times with the htmlarea RTE didn’t work anymore. A simple htaccess redirect (RewriteRule ^(.+)uploads/(.*?)$ /uploads/$2 [R,L]
    ) worked just in this case.

In my eyes, the real and true solution would be to

  1. get rid of all baseURL tags (in my eyes, it was and will always be just a dirty workaround).
  2. have realURL add the part of the mainsite directory to every relative path when rendering the HTML. There could be an option for multisites to dynamically add the domain to all links, using the domain records.

Category: TYPO3 | 12 Comments

Require to select a category for tt_news

Sunday, June 29th, 2008 | Author: Benni

If you have to customize a TYPO3 installation for your editors, and you use tt_news, you maybe have had the problem. Your editor gives you a call and let’s you know that he can’t see his just finished news in the frontend. You find out that the record is not hidden, but the problem is that the editor hasn’t had a category selected. Most likely it’s because the categories are on the second tab in the TCEforms. (in some cases where we “misue” tt_news, it’s the only thing that is on the second tab). However, the problem is then that the editor saves the record and forgets to attach a category to it. With this simple statement you can force the editor to select a category:

TCEFORM.tt_news.category.config.minitems = 1

This can be done on pagesTSconfig level but also on userTSconfig, and is quite helpful to save some support calls.

Category: TYPO3 | 6 Comments

TypoScript Magic: tt_news Title in Headline or Menu or somewhere

Friday, June 06th, 2008 | Author: Benni

In almost every TYPO3 project of mine, I use this awesomely generic tt_news for displaying news, top offers, etc. In many projects I also have a headline or a breadcrums menu somewhere, telling about the title of the page. tt_news itself offers the possibility to substitute the page title in the <title> tag, however I often use my own title tag rendering, or by using the excellent seo_basics extension :). So the tt_news title is not substituted at all. Therefore I always wrote this little TypoScript snippet that I can use everywhere: more…

Category: TYPO3 | 11 Comments

The good, the bad and the ugly: t3skin

Thursday, June 05th, 2008 | Author: Benni

Ever since the t3skin arrived, there was this nasty thing that bugged me so much: Some tabs in the TYPO3 Backend weren’t styled at all, and they still had the colors of the classic TYPO3 skin.

As of the nature of TYPO3, an installed skin just overrides the classic skin styles and icons, and it seems like the t3skin author forgot about that. The places where you can see these problems is when selecting a link (Element Browser, Browse Links) and inside the DAM. Apparantly these are the only occurences where the “tabMenu” functions from the template.php file are used, all other places (TCEforms) use the dynTabMenu whic is styled. more…

Category: TYPO3 | One Comment

Evolution Of My Footer Code - Part 1

Tuesday, June 03rd, 2008 | Author: Benni

Everybody started out very simple with TYPO3. In case of my projects, I had to update the copyright year, with all my clients of course. At first, I put everything static in my HTML template, so I had to change the year there. Then I put the static string in TypoScript. Nowadays I enjoy the power of TypoScript that automatically updates the year in the footer for me. This means less client calls at the beginning of the year :) more…

Category: TYPO3 | 3 Comments

Override LL-File Labels for a whole Installation

Tuesday, June 03rd, 2008 | Author: Benni

Today I found out something very nice.

I had the problem that I needed to redefine some labels for alanguage file in an extension. This was client-specific, so it wasn’t suitable for a patch to send to the corresponding extension developer. But I didn’t want to modify the extension files by myself, because in case of an upgrade, the changes would have been erased. So I stumbled upon this nice feature, which worked just fine for my TYPO3 4.0 installation. more…

Category: TYPO3 | One Comment