|
|
Welcome to my blog! I will be posting my latest photos, as well as code snippets, useful tricks & techniques, and whatever else is on my mind on a particular day. Oh, and please pardon my occasional Russian, when I am at loss for words to express myself... Enjoy your stay, and I appreciate your feedback, as well as constructive criticism.

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.
Tags: Doctrine, php, proxy, Zend Posted in Programming | No Comments »

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!
Tags: Doctrine, php, update, Zend Posted in Programming | 2 Comments »


Every year millions of monarch butterflies fly more than three thousand miles from Canada to Mexico, to the same mountains where a year earlier their grandparents spent the winter. This phenomenon is the migration of the Eastern Monarch. Last month I took the trip, organized by Expedition Travel, to the Transvolcanic mountain range in Mexico to witness the colonies of overwintering monarchs.



The monarchs in the colony were quite active, thanks to plenty of sunlight. Their generation took the trip in the fall of previous year from Canada down to Mexico, where they spent the winter clinging to trunks and branches of the Oyamel trees. Now they were mating and flying north to Texas. They would reach Texas in early spring, and females will lay eggs on young milkweed plants before dying. The generation born from the eggs will live for a month, and make the trip further north, reaching Alabama, Carolinas, etc. The generation after them will continue the path north, reaching Pennsylvania, Ohio, New York. They also live for a month. The following generation is called Methuselah generation, since they end up living nine times longer than the previous generations, fly up to Canada, and then make their way back to Mexico, flying close to 50 miles per day during the migration, and then spend five months at the overwintering site.

What motivates the monarch to take this dangerous trip? Their host plant – the milkweed is more abundant in North America, than it is in Central. Mexico has 6 species of milkweeds, while US has over a hundred. Yet, they can’t just stay in North America, since they can’t withstand temperatures below freezing being a tropical butterfly. Milkweed is poisonous, but Monarchs are able to digest it, and use it for protection against the predators. A bird that eats a monarch experiences a heart attack, and will not eat another monarch, or anything that looks like it (ex: Viceroy).




Monarchs take various paths in getting to Mexico. Some follow the coast down to Texas, feasting on flowers blooming thanks to the fall storms, then fly across the land to Mexico. Others fly down to Florida, to Cuba, then to Yucatan, then follow the land back North to the Transvolcanic range. Monarch’s wings are covered with scales that repel water, so they’re able to rest on the water, assuming the waves are not high, and then take off from the water. Not much more is known about the paths that monarchs take, but what is known has been discovered thanks to the Monarch Watch tagging program.


The monarch is a butterfly ruled by the sun. When the autumn sun reaches fifty two degrees above the horizon, monarch reproduction cycle shuts down, and migration is kicked off. The generation that flies to Mexico has never been there, yet they’re able to find the exact spot year after year where their grand-parents spent the winter. It is believed they use a combination of senses to reach their destination. They’re able to orient themselves to the sun by using polarized light. Then they’re able to sense the magnetic field of the earth thanks to small magnetic sensors in the base of their wings. This is also extremely helpful, since the mountains where they end up for the winter are of volcanic origin, and are thus rich in iron. Finally, the millions of monarchs every winter leave behind billions of microscopic scales, and its possible that the monarchs are able to detect these using chemical scents.



Once the monarchs reach their destination, they start accumulating in clusters, with the base butterfly holding on to the pine needle, and others holding on to its wings. These clusters can get several butterflies deep, with the temperature in the center of the cluster slightly higher than on the outside. But there is a danger, where a strong enough wind will cause the base monarch to lose grip and fall to the ground. Several mice in the region count on this, and are ready to eat the fallen butterflies. They even line their nests with monarch wings for decoration. Who can blame them?



There are several factors threatening the monarch migration. The biggest threat to them is illegal logging. A biosphere reserve protects the locations of largest colonies, but local villagers frequently cut wood in the forests. The hundred year old pines they cut are critical to Monarchs survival of the winter, because their trunk holds heat, and monarchs layer the tree trunk relying on this heat source.

Another major threat is climate change. The migration relies on the timing of key events, for instance flowers blooming in Texas as they key food source for monarchs, or milkweed plants hatching. Any shifting in the timing of these events could threaten the entire phenomenon. Other threats are due to overpopulation, where wild fields are plowed over and used for agriculture, pesticides that are used poison the land, etc. No one wants to kill the monarchs, but unfortunately, they end up being collateral damage. Hopefully, we can preserve this amazing sight for our future generations.

Tags: butterfly, migration, photos Posted in Photography, Travelog | 3 Comments »

It’s been a few months since I’ve posted anything on the blog. It’s not because I’m slacking off – quite the opposite, I’ve been extremely busy. But there is a lot to write about, and the post activity will increase. Starting now.
It’s always mesmerizing to watch the process of metamorphosis. Last summer I had that opportunity. We found a dragonfly larva on the trail near Lost Pond in White Mountains, New Hampshire. The larva was ready to hatch, so I took my spot with the camera, and got ready to film the emergence.
View the slideshow of the emergence

To my surprise, after drying off, the larva continued its journey inland, away from the water. I thought it was unusual, as most hatch just above the water, or right near it. This one was very determined, and all my attempts to place it on a photogenic plant failed.
After crawling three or four yards from the edge of the water, the larva reached a tree. Only then did I notice three other exuvia (empty shells left after the dragonfly emerges) on the trunk. This one crawled up to the side of one about 6 feet off the ground, and finally stopped.

One other interesting thing to notice, is that the larva was missing the middle leg on the right side – lost to a predator earlier in its life. The emerged dragonfly was also missing a leg in the same spot.



Metamorphosis like this fascinates humans. We are amazed by this transformation for several reasons. Mostly because even in the twenty first century we still don’t understand it fully. But also because we see deep symbolism in the change that the individuals undergo through. Indeed, occasionally it takes a radical transformation, but what emerges is much grander than what was before.
Tags: dragonfly, emergence, metamorphosis, photos Posted in Photography | No Comments »

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
Tags: book, packt, TYPO3 Posted in TYPO3 | No Comments »

|