function processDeletions() { // debug($this->options); $ids = $this->LocalModel->migrationDeletedIds($this->Process->targetInstance); if (!empty($ids)) { if (!empty($this->options['instance']['execeptions']) || !empty($this->options['execeptions']) && $this->options['mode'] != 'exclude') { if ($this->options['mode'] == 'exclude') { $ids = array_diff($ids, $this->options['instance']['execeptions']); } else { $ids = array_intersect($ids, $this->options['instance']['execeptions']); } } if (!empty($ids)) { $remoteModel = Migration::getRemoteModel($this->LocalModel, $this->Process->targetInstance); $dry = MigrationConfig::load('dryRun'); if ($dry) { $this->msg('Delete attempt on ' . $remoteModel->alias . ' for Ids : ' . implode(', ', $ids)); } else { if ($remoteModel->deleteAll(array($remoteModel->alias . '.' . $remoteModel->primaryKey => $ids))) { $this->msg(str_replace('%nb%', count($ids), __('%nb% entries deleted on the remote server', true))); $this->MigrationRemote->deleteAll(array('model' => $this->LocalModel->getFullName(), 'remote_id' => $ids)); } } } } }
function autoSolve() { while (($batch = $this->nextAutoSelectBatch()) || ($invalidated = $this->nextInvalidatedGroup())) { if ($batch) { $batch->process(); } else { foreach ($invalidated as $modelName => $ids) { $batch = $this->getBatchFor($modelName); $batch->reprocess($ids); } $dry = MigrationConfig::load('dryRun'); if ($dry) { break; } } } }
function createFoldersFor($file) { $folder = dirname($file); if (!file_exists($folder)) { App::import('Lib', 'Migration.MigrationConfig'); Migration::createFoldersFor($folder); $dry = MigrationConfig::load('dryRun'); if ($dry) { Migration::msg('Create folder : ' . $folder); return true; } else { return mkdir($folder); } } }
function updateMigrationTracking($Model, $data) { $settings = $this->settings[$Model->alias]; $MN = $this->MigrationNode; $fullName = $this->getFullName($Model); $gdata = array(); $dry = MigrationConfig::load('dryRun'); foreach ($data as $id => $tracked) { $gdata[(int) (bool) $tracked][] = $id; } //debug($gdata); $def = !$settings['manual']; if (!empty($gdata[(int) $def])) { if ($dry) { $this->msg('Update attempt on ' . $MN->alias); } else { $MN->updateAll(array('tracked' => null), array('model' => $fullName, 'local_id' => $gdata[(int) $def])); } } if (!empty($gdata[(int) (!$def)])) { if ($dry) { $this->msg('Update attempt on ' . $MN->alias); } else { $MN->updateAll(array('tracked' => (int) (!$def)), array('model' => $fullName, 'local_id' => $gdata[(int) (!$def)])); } $existent = $MN->find('list', array('fields' => array('id', 'local_id'), 'conditions' => array('model' => $fullName, 'local_id' => $gdata[(int) (!$def)]))); foreach (array_diff($gdata[(int) (!$def)], $existent) as $id) { $MN->create(); $node = array('model' => $fullName, 'local_id' => $id, 'tracked' => (int) (!$def)); if ($dry) { $this->msg('Save attempt on ' . $MN->alias); } else { $MN->save($node); } } } }
function checkWasMissing() { $localId = $this->getLocalId(); $fullName = $this->LocalModel->getFullName(); $MR = $this->MigrationRemote; $MMissing = $this->MigrationMissing; $toInvalidate = $MMissing->find('all', array('conditions' => array($MR->alias . '.instance' => $this->targetInstance, $MMissing->alias . '.model' => $fullName, $MMissing->alias . '.local_id' => $localId), 'recursive' => 0)); $idsToInvalidate = array(); foreach ($toInvalidate as $inv) { $idsToInvalidate[] = $inv[$MMissing->alias]['migration_remote_id']; $this->Batch->Process->invalidated[] = array('model' => $inv[$MR->alias]['model'], 'local_id' => $inv[$MR->alias]['local_id']); } if (!empty($toInvalidate)) { $dry = MigrationConfig::load('dryRun'); if ($dry) { $this->msg('Update attempt on ' . $MR->alias); } else { $MR->updateAll(array('invalidated' => 1), array('id' => array_values($idsToInvalidate))); } } }
function admin_index() { App::import('Lib', 'Migration.Migration'); App::import('Lib', 'Migration.MigrationProcess'); $targets = Migration::targetList(); if (empty($targets)) { $this->render('admin_missing_target'); return; } //$Model = Migration::getLocalModel('Slider'); //debug($Model->migrationDeletedCount()); // $Model = Migration::getLocalModel('Page'); // debug($Model->migrationDeletedCount()); $posted = !empty($this->data); if ($posted) { foreach ($this->data['Migration']['targets'] as $target => $active) { if ($active) { $process = new MigrationProcess($target); foreach ($this->data['Migration']['models'] as $modelName => $active) { if ($active) { $modelName = str_replace('-', '.', $modelName); //$process->models[$modelName] = $this->Migrated->findOpt($modelName); $process->setModelOpt($modelName, $this->Migrated->getModelOpt($modelName)); } } // debug($process->models); $process->run(); $this->Session->setFlash(implode("<br>\n", $process->msgs)); } } $dry = MigrationConfig::load('dryRun'); if ($dry) { $this->data = array(); $posted = false; } else { $this->Migrated->clear(); $this->redirect(array('action' => 'index')); } } $modelsNames = Migration::migratingModels(); $models = array(); $pendings = Migration::pendingList(); foreach ($modelsNames as $mname) { $m = array('class' => Migration::classNameParts($mname, 'class'), 'name' => str_replace('.', '-', $mname), 'count' => 0, 'deleted_count' => 0, 'migrated_count' => 0, 'param' => Migration::modelNameToUrl($mname)); if (!empty($pendings[$mname])) { $m['count'] = array_sum($pendings[$mname]); $m['deleted_count'] = empty($pendings[$mname]['delete']) ? 0 : $pendings[$mname]['delete']; $m['migrated_count'] = $this->Migrated->alterCount($mname, $m['count']); if (!$posted) { $this->data['Migration']['models'][$m['name']] = 1; } } $models[] = $m; } // debug($models); if (!$posted) { foreach ($targets as $key => $label) { $this->data['Migration']['targets'][$key] = 1; } } $this->set('models', $models); $this->set('targets', $targets); }