tine20: Zend Framework upgrade from version 1.6 to 1.8.4

As mentioned by Lars in http://lars.kneschke.de/index.php?/archives/80-New-Tine-2.0-team-member-Jonas.html and reported in http://www.tine20.org/bugtracker/bug_update_page.php?bug_id=620, one of my first steps in tine20 development was updating the zend framework library files from version 1.6 to the latest stable version 1.8.4.

Because I could not find any Zend Framework upgrade guide or the like, I jotted down the major pitfalls I had to deal with.

Zend_Autoloader => Zend_Loader_Autoload

http://framework.zend.com/manual/en/zend.loader.autoloader.html
One of the more obvious changes concerned the autoloader:

Instead of

require_once ‘Zend/Loader.php’;
Zend_Loader::registerAutoload();

it now reads

require_once ‘Zend/Loader/Autoloader.php’;
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->setFallbackAutoloader(true);

It is also possible to register autoloading namespaces but as tine20 has not one single class namespace but many per-application namespaces I decided to simply rely on the fallback autoloader.

Zend_Locale and Caching

http://framework.zend.com/manual/en/zend.locale.html#zend.locale.cache

Zend_Locale now automatically uses Zend_Cache to improve its performance. This led to an open_basedir_restriction on my system because it set the cache_dir using Zend_Cache_Backend::getTmpDir which returned ‘/tmp in my case which was not allowed within my php.ini.

As I already had a properly configured Zend_Cache Instance, I injected this into Zend_Locale using Zend_Locale::setCache($cache). Anyway, it is also possible to disable chaching for Zend_Locale with Zend_Locale::disableCache(true);.

Zend_Locale::isLocale

See http://zendframework.com/manual/de/zend.locale.migration.html#zend.locale.migration.fromonesixtooneseven

Zend_Locale::getLanguageTranslationList is now static

Zend_Locale::getLanguageTranslationList is now a static method so you need to inject your own locale object otherwise the method will implicitly guess a locale.

For example I had to change a method that returned a list of country names translated to the given locale’s language:

//old
$countries = $locale->getCountryTranslationList();
//new
$countries = Zend_Locale::getCountryTranslationList($locale);

With the old code that always returned the country list translated to the automatically guessed language (depending on my browser settings), no matter what language had been set in $locale.

Note: Zend_Locale::getTranslationList will be marked as deprecated since Zend Framework 1.9.

Validator/Filter Changes in 1.8.2

The InArray Filter does not validate correctly if one of the accepted values is “empty”, e.g. false, null, 0.
In this case you have to additionally set allowEmpty => true and  ‘presence’ => ‘required’. That works together with default values as well:

For example I had to change

$this->_validators = array(
‘booleanFieldName’ => array(
new Zend_Validate_InArray(array(TRUE, FALSE), TRUE),
‘default’ => FALSE
),
)

to

$this->_validators = array(
‘booleanFieldName’ => array(
new Zend_Validate_InArray(array(TRUE, FALSE), TRUE),
‘default’ => FALSE,
‘presence’ => ‘required’,
‘allowEmpty’ => TRUE
),
)

Another validation problem ocurred when validating the presence of null values. Null values are treated as missing data instead of an empty value. Since revision 15646 the presence of a field is checked using isset() instead of array_key_exists which results in null values being recognized as not present. This backward incompatibility issue is reported in http://framework.zend.com/issues/browse/ZF-7135 but not yet fixed in the trunk.
For tine20 I patched the file and we will keep an eye on the ZF-7135 issue.

UPDATE: In http://zendframework.com/issues/browse/ZF-7220 the same issue is discussed and Matthew Weier O’Phinney comments: “If a field is required, it cannot be empty. HTML forms will submit either an empty string for a value, or not submit the value at all (this latter is true only of checkboxes and buttons). In terms of validation, if we allow empty strings, but simultaneously require the element, we have no reasonable mechanism to test – one or the other can be true, but not both.

Marking as “won’t fix”, as this design was determined after much community discussion, and changing the behavior would be a BC break.”

Zend_Json_Server

tine20 has been using the Zend_Json_Server class from the incubator which is now part of the official Zend Framework release. However, the public interface and the whole process flow within this class changed a lot and I could not yet adjust the tine20 to use the latest version. This is an on-going todo.

Conclusion

There have been some backward compatibility issues but most of them have been detected by the php parser. And with our unit tests in place the update went pretty smoothly – so far.

One Response to “tine20: Zend Framework upgrade from version 1.6 to 1.8.4”

  1. [...] just updated tine20 to use the latest stable Zend Framework version (1.9.1). Similarly to upgrading from 1.6 to 1.8 the upgrade from 1.8.4 to 1.9.1 went pretty painless except some validation [...]

Leave a Reply