/**
  * Move digital objects to repository specific paths like
  * http://code.google.com/p/qubit-toolkit/source/detail?r=9503
  *
  * @return QubitMigrate110 SELF
  */
 protected function updatePathToAssets()
 {
     // Create "uploads/r" subdirectory
     if (!file_exists(sfConfig::get('sf_upload_dir') . '/r')) {
         mkdir(sfConfig::get('sf_upload_dir') . '/r', 0775);
     }
     foreach ($this->data['QubitDigitalObject'] as $key => &$item) {
         if (!isset($item['information_object_id'])) {
             continue;
         }
         // Get the related information object
         $infoObject = $this->getRowByKeyOrId('QubitInformationObject', $item['information_object_id']);
         if (null === $infoObject) {
             continue;
         }
         // Recursively check info object ancestors for repository foreign key
         while (!isset($infoObject['repository_id']) && isset($infoObject['parent_id'])) {
             $infoObject = $this->getRowByKeyOrId('QubitInformationObject', $infoObject['parent_id']);
         }
         // Get repository
         if (isset($infoObject['repository_id'])) {
             $repo = $this->getRowByKeyOrId('QubitRepository', $infoObject['repository_id']);
             if (!isset($repo['slug'])) {
                 continue;
             }
             $repoName = $repo['slug'];
         } else {
             $repoName = 'null';
         }
         // Update digital object and derivatives paths
         foreach ($this->data['QubitDigitalObject'] as $key2 => &$item2) {
             if ($key == $key2 || isset($item2['parent_id']) && $key == $item2['parent_id']) {
                 // Don't try to move remote assets
                 $externalUriKey = $this->getTermKey('<?php echo QubitTerm::EXTERNAL_URI_ID."\\n" ?>');
                 if ($externalUriKey == $item2['usage_id']) {
                     continue;
                 }
                 $oldpath = $item2['path'];
                 // Build new path
                 if (preg_match('|\\d/\\d/\\d{3,}/$|', $oldpath, $matches)) {
                     $newpath = '/uploads/r/' . $repoName . '/' . $matches[0];
                 } else {
                     continue;
                 }
                 if (!file_exists(sfConfig::get('sf_web_dir') . $newpath)) {
                     if (!mkdir(sfConfig::get('sf_web_dir') . $newpath, 0775, true)) {
                         continue;
                     }
                 }
                 if (file_exists(sfConfig::get('sf_web_dir') . $oldpath)) {
                     if (!rename(sfConfig::get('sf_web_dir') . $oldpath . $item2['name'], sfConfig::get('sf_web_dir') . $newpath . $item2['name'])) {
                         continue;
                         // If rename fails, don't update path
                     }
                 }
                 // Delete old dirs, if they are empty
                 QubitDigitalObject::pruneEmptyDirs(sfConfig::get('sf_web_dir') . $oldpath);
                 // Update path in yaml file
                 $item2['path'] = $newpath;
             }
         }
     }
     return $this;
 }