I've implemented my classs who extends migrate, it imports all the rows correctly from a MySql database, but i must repeat this cycle every day and i must delete all data before import.
I've tried to implement Migration::replace() in the beforeImport() istance, but seems it doesn't work. How can I implement it?

thanks

Comments

mikeryan’s picture

Version: 7.x-2.5-rc2 » 7.x-2.x-dev
Category: task » support
Status: Active » Postponed (maintainer needs more info)

Sorry I missed this post - "support request" is a better category for questions like this.

You can run

$ drush migrate-import --rollback MyMigration

To automatically rollback before importing. If you're doing this on a daily basis, scheduling that command in crontab would be a good idea.

csedax90’s picture

i've write this function to run cron every night... is it correct?

function import_anagrafica_cron(){
	$execute_import = import_anagrafica_check_if_update();
	if($execute_import == TRUE){
		$limit = array();
		$limit['value'] = 200000; //limita il numero di cancellazioni o importazioni
		$limit['unit'] = "items";
		
		$migration = Migration::getInstance('MigrateAnagraficaToNode'); //sostituire con il nome di migrate
		
		//Elimino tutti i dati
		$migration->processRollback(array('limit' => $limit, 'force' => TRUE));
		
		//Importo gli elementi
		$migration->processImport(array('limit' => $limit));
	}
	else{
		watchdog('Migrate', "Non è stato necessario un aggiornamento", array(), WATCHDOG_INFO);
	}
}

the process is running but it seems very slow... i've written some wrong code?
thanks for your support!

mikeryan’s picture

Be sure when adding information to an issue marked "postponed (maintainer needs more info)", that you reset the status to "active" - issues with the postponed status get bottom priority when reviewing the queue, the assumption being that there is nothing new there.

Migration processes are a bit heavy to be run in a cron hook - Drupal cron is intended to run for a limited time (like, a minute or two) on each invocation, and a big process like this will block other cron functions. You're really better off running migrations directly from the server's crontab.

As for your performance issue, the best way to diagnose this is to try running the rollback and import operations through drush with the --instrument=timer flag - this will report where most of the time is being spent so you can find your bottlenecks.

csedax90’s picture

Status: Postponed (maintainer needs more info) » Active

thanks, your support is very usefull! But... how can i set up to run the module with the crontab? I should write a command to execute drush + migrate?

thanks for your time!

ziobudda’s picture

Hi CRY_X2, create a file "mio _script_migrate.php" in the "scripts" directory and write this code:

<?php

define('DRUPAL_ROOT', getcwd());

include_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
$_SERVER['REMOTE_ADDR'] = 'localhost';

import_anagrafica_cron();

In the crontab write something like:

0 * * * * cd /MY/DRUPAL/ROOT/FULL/PATH && php scripts/mio _script_migrate.php

This run you function every hour at 00 minute.
If you want to run this script more time in 1 hour write */EVERY_HOW_MANY_MINUTES_IN_NUMBER in place of 0

M.

PS: Spero di esseri stato d'aiuto.

mikeryan’s picture

Status: Active » Postponed (maintainer needs more info)

You don't even need to wrap a script around it:

0 * * * * drush -r /my/drupal/root mi --update MigrateAnagraficaToNode
mikeryan’s picture

Status: Postponed (maintainer needs more info) » Closed (works as designed)
csedax90’s picture

thanks all, after a couple of testing and days my process works correctly!

PS: grazie ziobudda funziona tutto alla grande