function nextAutoSelectBatch()
 {
     if (!empty($this->autoSelect)) {
         $modelName = $this->autoSelect[0]['model'];
         $ids = array();
         foreach ($this->autoSelect as $i => $sel) {
             $ids[] = $sel['local_id'];
             unset($this->autoSelect[$i]);
         }
         $this->autoSelect = array_values($this->autoSelect);
         $Model = Migration::getLocalModel($modelName);
         $this->batches[] = $batch = new MigrationBatch($this, $Model, array('conditions' => array($Model->alias . '.' . $Model->primaryKey => $ids)));
         return $batch;
     }
 }
 function updateAllTracking($data)
 {
     //debug($data);
     foreach ($data as $model => $mdata) {
         $Model = Migration::getLocalModel($model);
         $Model->updateMigrationTracking($mdata);
     }
 }
 function prepDataForMigration($exclude = array())
 {
     // $this->LocalModel, $this->entry, $this->targetInstance
     // $Model, $entry, $targetInstance,
     $settings = $this->LocalModel->migrationSettings();
     $exclude = array_merge($exclude, array($this->LocalModel->primaryKey), $settings['excludeFields']);
     $fullName = $this->LocalModel->getFullName();
     $alias = $this->LocalModel->alias;
     $entry = $this->entry;
     $assoc = $this->LocalModel->getMigratedAssociations();
     if (!empty($assoc)) {
         foreach ($assoc as $name => $opt) {
             $paths = array();
             if (!empty($opt['path'])) {
                 $paths = Migration::extractPath($entry[$alias], $opt['path']);
             } elseif (!empty($opt['foreignKey']) && array_key_exists($opt['foreignKey'], $entry[$alias])) {
                 $paths = array($opt['foreignKey'] => $entry[$alias][$opt['foreignKey']]);
             }
             //debug($paths);
             if (!empty($paths)) {
                 $AssocModel = Migration::getLocalModel($opt['className']);
                 foreach ($paths as $path => $local_id) {
                     $removed = false;
                     $remote_id = $AssocModel->getRemoteId($local_id, $this->targetInstance);
                     if (is_null($remote_id)) {
                         if (isset($opt['unsetLevel'])) {
                             $entry[$alias] = Set::remove($entry[$alias], implode('.', array_slice(explode('.', $path), 0, $opt['unsetLevel'])));
                             $removed = true;
                         }
                         if (!empty($opt['autoTrack'])) {
                             $entry['MigrationTracking'][$opt['className']][$local_id] = 1;
                         }
                         if (!empty($opt['autoSelect'])) {
                             $this->Batch->Process->autoSelect[] = array('model' => $opt['className'], 'local_id' => $local_id);
                         }
                         $entry['MigrationMissing'][] = array('model' => $opt['className'], 'local_id' => $local_id);
                     }
                     if (!$removed) {
                         $entry[$alias] = Set::insert($entry[$alias], $path, $remote_id);
                     }
                 }
             }
         }
         //debug($assoc);
     }
     //debug($entry[$alias]);
     $raw = $this->LocalModel->getRawEntry($entry);
     $data = $raw[$alias];
     $data = array_diff_key($data, array_flip($exclude));
     $entry['MigrationData'] = $data;
     return $entry;
 }
 function admin_deleted($instance, $modelName, $id)
 {
     App::import('Lib', 'Migration.Migration');
     $Model = Migration::getLocalModel($modelName);
     $remoteModel = Migration::getRemoteModel($Model, $instance);
     $remote = $remoteModel->read(null, $id);
     $this->set('modelUrlAlias', $Model->getUrlName());
     $this->set('modelAlias', $remoteModel->alias);
     $this->set('remote', $remote);
 }