diff --git a/sites/all/modules/unl/unl_migration.php b/sites/all/modules/unl/unl_migration.php index 0b8f41f855d1afa82fd132ec2af9783b4effce62..57412536eb867d2764d0460beb5ecfab352f5936 100644 --- a/sites/all/modules/unl/unl_migration.php +++ b/sites/all/modules/unl/unl_migration.php @@ -2,9 +2,22 @@ function unl_migration($form, &$form_state) { + if ($form_state['rebuild']) { + $form['root'] = array( + '#type' => 'fieldset', + '#title' => 'This is taking a while. Click continue.' + ); + $form['root']['submit'] = array( + '#type' => 'submit', + '#value' => 'Continue', + ); + return $form; + } + + $form['root'] = array( '#type' => 'fieldset', - '#title' => 'Migration Tool' + '#title' => 'Migration Tool', ); $form['root']['site_url'] = array( @@ -44,8 +57,12 @@ function unl_migration($form, &$form_state) return $form; } -function unl_migration_submit($form, &$form_state) -{ +function unl_migration_submit($form, &$form_state) { + if (isset($form_state['storage']) && file_exists($form_state['storage'])) { + $migration = unserialize(file_get_contents($form_state['storage'])); + unlink($form_state['storage']); + } + else { $migration = new Unl_Migration_Tool( $form_state['values']['site_url'], $form_state['values']['frontier_path'], @@ -53,7 +70,17 @@ function unl_migration_submit($form, &$form_state) $form_state['values']['frontier_pass'], $form_state['values']['ignore_duplicates'] ); - while (!$migration->migrate()); + } + + if ($migration->migrate()) { + $form_state['rebuild'] = FALSE; + return; + } + + $form_state['rebuild'] = TRUE; + $migration_storage_file = drupal_tempnam(file_directory_temp(), 'unl_migration_'); + $form_state['storage'] = $migration_storage_file; + file_put_contents($migration_storage_file, serialize($migration)); } @@ -100,11 +127,12 @@ class Unl_Migration_Tool * Keep track of the state of the migration progress so that we can resume later * @var int */ - private $_state = self::STATE_NONE; - const STATE_NONE = 1; - const STATE_PROCESSING_PAGES = 2; - const STATE_CREATING_NODES = 3; - const STATE_DONE = 4; + public $_state = self::STATE_NONE; + const STATE_NONE = 1; + const STATE_PROCESSING_BLOCKS = 2; + const STATE_PROCESSING_PAGES = 3; + const STATE_CREATING_NODES = 4; + const STATE_DONE = 5; public function __construct($baseUrl, $frontierPath, $frontierUser, $frontierPass, $ignoreDuplicates) { @@ -131,16 +159,23 @@ class Unl_Migration_Tool $this->_baseUrl = $baseUrl; $this->_addSitePath(''); - $this->_curl = curl_init(); - $this->_frontierScan('/'); } - public function migrate($time_limit = 1) + public function migrate($time_limit = 30) { $start_time = time(); ini_set('memory_limit', -1); - + if ($this->_state == self::STATE_NONE) { + $this->_frontierScan(''); + + $this->_state = self::STATE_PROCESSING_BLOCKS; + if (time() - $start_time > $time_limit) { + return FALSE; + } + } + + if ($this->_state == self::STATE_PROCESSING_BLOCKS) { // Parse the menu $this->_processMenu(); $this->_process_blocks(); @@ -697,6 +732,9 @@ class Unl_Migration_Tool private function _getUrl($url) { + if (!$this->_curl) { + $this->_curl = curl_init(); + } $url = strtr($url, array(' ' => '%20')); curl_setopt($this->_curl, CURLOPT_URL, $url); curl_setopt($this->_curl, CURLOPT_RETURNTRANSFER, TRUE); @@ -834,6 +872,10 @@ class Unl_Migration_Tool $files = array(); foreach ($rawFileList as $index => $rawListing) { $file = substr($fileList[$index], strlen($ftpPath)); + if (in_array($file, array('_notes', '_baks'))) { + continue; + } + if (substr($rawListing, 0, 1) == 'd') { //file is a directory $this->_frontierScan($path . $file . '/');