Posted by & filed under News & Politics.

There has been a lot of talk in the media lately about the future of the Android operating system. The trigger this time was the resignation of Android chief Andy Rubin.

One post in particular has caught my attention. Rather than focusing on Andy’s departure, it shines light on┬áSundar Pichai, currently head of Chrome OS project, who will be taking over Android. The article then claims Chrome OS and Android will merge and achieve what Windows 8 could not – single platform running on full gamut of devices.

The article is wrong on one fundamental level – Chrome OS and Android are completely different systems, designed with different goals in mind. Merging them together is simply impossible, one would cease to exist in the process. What can happen is feature migration from one to another. Chrome OS has the goal of proving the Web to be a viable operating system, with all data stored in the cloud, and the physical device being only a thin client accessing that data. It’s a great project, but is still an esoteric system, not for everyday use.

It’s hard to predict the future, especially in technology. Chrome OS and Android may one day merge, but I doubt it. Likewise, I don’t expect Android in the current state to run on a laptop, much like Gingerbread wasn’t meant to be run on tablets. Both technologies will evolve, shaped by Google, Google’s hardware partners, application developers, and the users. Where we end up is anyone’s guess.

Full disclosure: I’ve dedicated countless hours to application development on Android, and am heavily invested in its future.

Posted by & filed under News & Politics.

I updated my site & blog for 2013, making it more responsive and mobile-friendly.

As part of the redesign, I created a plugin to WordPress, connecting to my 500px account. It pulls in my profile once a day, posting any new photographs to the blog. This automated posting saves me from posting to the site manually, so hurray for laziness. I published the plugin on github under an MIT license if anyone is interested.

Best of luck in the new year!

Posted by & filed under Programming.

Doctrine 2.0 documentation recommends against serializing entities. If you ignore the documentation, you will be faced with PHP notices, such as

Notice: Unknown: "id" returned as member variable from __sleep() but does not exist in Unknown on line 0

as well as broken object relations on unserialized objects. But its very tempting to use the entities in situations that implicitly require serialization – for example in Zend_Auth. A “User” entity used in Zend_Auth would be written to session, and thus serialized implicitly, creating the already mentioned problems.

However, its relatively easy to create a proxy to the entity. For example:


class UserProxy {
    protected $entity;
    protected $identity;
   
    public function __construct($entity)
    {
        $this->entity = $entity;
        // Get the identifier from the entity
        $this->identity = $this->entity->getId();
    }
   
    public function __call($name, $arguments)
    {
        return call_user_func_array(
            array($this->entity, $name),
            $arguments);
    }
   
    public function __sleep()
    {
        return array('identity');
    }
   
    public function __wakeup()
    {
        $this->restore();
    }
   
    protected function restore()
    {
        if (!empty($this->identity)) {
        // Replace with however you get
        // the entity manager
        $entityManager = Zend_Registry::get('em');
        $this->entity = $entityManager
            ->find('User', $this->identity);
    }
}

Now you just use the proxy in place of the entity in situations requiring serialization.


$toSerialize = new UserProxy($userEntity);

Any method calls made to the Proxy will be forwarded to the entity by the magic method. If the Proxy object is serialized, upon waking up, it will use the identifier to restore the entity.

Posted by & filed under Programming.

Those of you using Bisna library to easily hook Doctrine 2 ORM into Zend Framework, may find that it is incompatible with Doctrine 2.1. The reason is the rewritten annotation reader in Doctrine 2.1, which Bisna doesn’t support. However, its easy to update it.

In Bisna/Application/Container/DoctrineContainer.php, find the method startORMMetadata (should be the last method in the file), and replace it with the following (apologies for messed up indentation :():


private function startORMMetadata(array $config = array())
{
$metadataDriver = new \Doctrine\ORM\Mapping\Driver\DriverChain();

// Default metadata driver configuration
$defaultMetadataDriver = array(
'adapterClass' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'mappingNamespace' => '',
'mappingDirs' => array(),
'annotationReaderClass' => 'Doctrine\Common\Annotations\AnnotationReader',
'annotationReaderCache' => $this->defaultCacheInstance,
'annotationReaderNamespaces' => array()
);

foreach ($config as $driver) {
$driver = array_replace_recursive($defaultMetadataDriver, $driver);

// Register the ORM Annotations in the AnnotationRegistry
\Doctrine\Common\Annotations\AnnotationRegistry::registerFile(
APPLICATION_PATH . '/../library/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php');

$reflClass = new \ReflectionClass($driver['adapterClass']);
$nestedDriver = null;

if (
$reflClass->getName() == 'Doctrine\ORM\Mapping\Driver\AnnotationDriver' ||
$reflClass->isSubclassOf('Doctrine\ORM\Mapping\Driver\AnnotationDriver')
) {
$annotationReaderClass = $driver['annotationReaderClass'];
$reader = new $annotationReaderClass();
$reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\');
$reader->setIgnoreNotImportedAnnotations(true);
$reader->setEnableParsePhpImports(false);

foreach ($driver['annotationReaderNamespaces'] as $alias => $namespace) {
$reader->setAnnotationNamespaceAlias($namespace, $alias);
}

$annotationReader = new \Doctrine\Common\Annotations\CachedReader(
new \Doctrine\Common\Annotations\IndexedReader($reader),
new \Doctrine\Common\Cache\ArrayCache()
);
$nestedDriver = $reflClass->newInstance($annotationReader, $driver['mappingDirs']);
} else {
$nestedDriver = $reflClass->newInstance($driver['mappingDirs']);
}

$metadataDriver->addDriver($nestedDriver, $driver['mappingNamespace']);
}

if (($drivers = $metadataDriver->getDrivers()) && count($drivers) == 1) {
reset($drivers);
$metadataDriver = $drivers[key($drivers)];
}

return $metadataDriver;
}

You should be good to go. Hopefully this saved you some time in research. I’ll try to push this update to github as well.

Any comments about missed configuration options are always welcomed!

Posted by & filed under TYPO3.

TYPO3 4.2 E-Commerce book cover image I was recently asked to review a new book from Packt Publishing, TYPO3 4.2 E-Commerce, written by Inese Liberte and Edgars Karlsons. TYPO3 is an excellent content management system designed for all types of websites, but there is very little information about building e-commerce shops – until now that is. While my TYPO3 experience is very recent, my e-commerce background dates back to late 90’s – so I was very excited to read this book.

First, let me state that although the book title implies the book is written for TYPO3 version 4.2 (which is deprecated now), the content applies equally well for the most recent version of TYPO3 4.4 (same is the case for my book). Second, I expected this book to be targeted at TYPO3 integrators – programmers who need to set up shops. Instead, this book is aimed at small, DIY business owners, trying their foot in e-commerce. The preface promises to walk the reader through setting up the site from scratch to build a profitable web presence. This is somewhat conflicting, as I found that some knowledge about TYPO3 is already required to begin reading this book.

One major issue I stumbled across is the lack of coherent flow in the book. This causes the reader to jump back and forth, as some sections don’t make sense until after subsequent chapters are read. This also leads to a lot of repeated content, and in general makes the book tough to follow. Let me walk through the chapters of the book and provide a better path to follow.

Chapters 1 & 2 cover basic TYPO3 installation, upgrades, templates, typoscript, and extension installation. Enough typoscript is given to confuse a newbie, so these chapters should only be read after some experience with TYPO3 basics. Likewise, if you’ve built a TYPO3 powered site before, you can safely skip this section.

Chapter 3 delves into the core of the book and describes the available commerce extensions. The description is very light, but the reader is instructed to consult the extension manuals for more information. The main extension chosen for the rest of the book is tt_products. Setting up a test paypal account is covered in detail, however most of the details of integrating it with TYPO3 and tt_products are left missing.

Chapter 4 starts by covering content import from CSV files, which is a bit premature at this point. It then explains adding new product using standard TYPO3 record editing features, and explains how to add a tt_products content element to a page. This is a chapter I would recommend rereading after experimenting with the shop setup.

Chapter 5 jumps into user registration, and covers frontend users and user groups. For commerce specific information, the book explains how to setup discounts for returning users.

The next chapter, chapter 6, diverges into menus, sitemap, navigation, and search. A lot of typoscript code is presented, but very little is explained, so the reader is expected to have a good foundation of typoscript at this point.

Chapter 7 provides a very light coverage of order management – something I would have liked to see more of, as it is arguably the most important step in the e-commerce flow after making a sale. No workflows, supply chains, or customer notifications are mentioned. The chapter also covers the basics of SSL and its integration into TYPO3. It also describes payment addins – something that was promised in chapter 3.

Chapter 8 gives an overview of the backend administration. Very little commerce specific information is given, and ideally this chapter should follow the installation chapter. Experienced TYPO3 users can safely skip this chapter.

Chapter 9 gives a top level of SEO optimization techniques. This is a topic that whole books could be, and have been, written on. Some TYPO3 specific information is given, but I would have preferred to see more.

Chapter 10 closes out the book by providing general tips for e-commerce, starting with basic business principles and ideas, and ending with site layout. This information is great for shop owners, but not for technical implementers. No TYPO3 specific information is given.

I was disappointed in not finding any information about TYPO3 and Magento integration, as that is a very popular topic. Unfortunately, its not covered at all in the book.

As a summary, if you were just starting out your TYPO3 e-commerce journey, I would recommend that you get some other introductory TYPO3 books (Building websites with TYPO3 by Michael Peacock and TYPO3: Enterprise Content Management at the minimum). Only then will you have a good foundation for this book, but then some of the chapters would become irrelevant.

If you want to see the language and type of information covered in the book, you can download a sample chapter.

TYPO3: Enterprise Content Management