Пример #1
0
 static function init()
 {
     if (g1_import::$init) {
         return;
     }
     $albums_path = module::get_var('g1_import', 'albums_path');
     if (empty($albums_path)) {
         throw new Exception('@todo G1_IMPORT_NOT_CONFIGURED');
     }
     g1_import::$init = g1_import::check_config($albums_path);
 }
 public function index()
 {
     if (g1_import::is_configured()) {
         g1_import::init();
     }
     $view = new Admin_View('admin.html');
     $view->page_title = t('Gallery 1 import');
     $view->content = new View('admin_g1_import.html');
     if (is_dir(g1_import::$album_dir)) {
         $view->content->g1_stats = $g1_stats = g1_import::g1_stats();
         $view->content->g3_stats = $g3_stats = g1_import::g3_stats();
         $view->content->g1_sizes = g1_import::common_sizes();
         $view->content->g1_version = g1_import::version();
         // Don't count tags because we don't track them in g1_map
         $view->content->g1_resource_count = $g1_stats['users'] + $g1_stats['groups'] + $g1_stats['albums'] + $g1_stats['photos'] + $g1_stats['movies'] + $g1_stats['comments'];
         $view->content->g3_resource_count = $g3_stats['user'] + $g3_stats['group'] + $g3_stats['album'] + $g3_stats['item'] + $g3_stats['comment'] + $g3_stats['tag'];
     }
     $view->content->form = $this->_get_import_form();
     $view->content->version = '';
     $view->content->thumb_size = module::get_var('gallery', 'thumb_size');
     $view->content->resize_size = module::get_var('gallery', 'resize_size');
     if (g1_import::is_initialized()) {
         if (count(g1_import::$warn_utf8) > 0) {
             message::error(t('Your G1 contains %count folder(s) containing nonstandard characters that G3 doesn\'t work with: <pre>%names</pre>Please rename the above folders in G1 before trying to import your data.', array('count' => count(g1_import::$warn_utf8), 'names' => "\n\n  " . implode("\n  ", g1_import::$warn_utf8) . "\n\n")));
         }
         if ((bool) ini_get('eaccelerator.enable') || (bool) ini_get('xcache.cacher')) {
             message::warning(t('The eAccelerator and XCache PHP performance extensions are known to cause issues.  If you\'re using either of those and are having problems, please disable them while you do your import.  Add the following lines: <pre>%lines</pre> to gallery3/.htaccess and remove them when the import is done.', array('lines' => "\n\n  php_value eaccelerator.enable 0\n  php_value xcache.cacher off\n  php_value xcache.optimizer off\n\n")));
         }
         foreach (array('notification', 'search', 'exif') as $module_id) {
             if (module::is_active($module_id)) {
                 message::warning(t('<a href="%url">Deactivating</a> the <b>%module_id</b> module during your import will make it faster', array('url' => url::site('admin/modules'), 'module_id' => $module_id)));
             }
         }
     } else {
         if (g1_import::is_configured()) {
             $view->content->form->configure_g1_import->albums_path->add_error('invalid', 1);
         }
     }
     print $view;
 }
Пример #3
0
 static function import($task)
 {
     $start = microtime(true);
     g1_import::init();
     $stats = $task->get('stats');
     $done = $task->get('done');
     $total = $task->get('total');
     $completed = $task->get('completed');
     $mode = $task->get('mode');
     $queue = $task->get('queue');
     if (!isset($mode)) {
         $stats = g1_import::g1_stats();
         $stats['items'] = $stats['photos'] + $stats['movies'];
         unset($stats['photos']);
         unset($stats['movies']);
         $stats['fix'] = 1;
         $task->set('stats', $stats);
         $task->set('total', $total = array_sum(array_values($stats)));
         $completed = 0;
         $mode = 0;
         $done = array();
         foreach (array_keys($stats) as $key) {
             $done[$key] = 0;
         }
         $task->set('done', $done);
     }
     $modes = array('users', 'albums', 'items', 'comments', 'highlights', 'fix', 'done');
     while (!$task->done && microtime(true) - $start < 1.5) {
         if ($done[$modes[$mode]] >= $stats[$modes[$mode]]) {
             // Nothing left to do for this mode.  Advance.
             $mode++;
             $task->set('last_id', 0);
             $queue = array();
             // Start the loop from the beginning again.  This way if we get to a mode that requires no
             // actions (eg, if the G1 comments module isn't installed) we won't try to do any comments
             // queries.. in the next iteration we'll just skip over that mode.
             if ($modes[$mode] != 'done') {
                 continue;
             }
         }
         switch ($modes[$mode]) {
             case 'users':
                 $done['users'] = $stats['users'] - 1;
                 $task->status = t('Ignoring users (%count of %total)', array('count' => $done['users'], 'total' => $stats['users']));
                 break;
             case 'albums':
                 if (empty($queue)) {
                     if (count(g1_import::$tree) == 0) {
                         g1_import::g1_stats();
                     }
                     $task->set('queue', $queue = array('' => g1_import::$tree));
                 }
                 $log_message = g1_import::import_album($queue);
                 if ($log_message) {
                     $task->log($log_message);
                 }
                 $task->status = t('Importing albums (%count of %total)', array('count' => $done['albums'] + 1, 'total' => $stats['albums']));
                 break;
             case 'items':
                 if (empty($queue)) {
                     if (count(g1_import::$queued_items) == 0) {
                         g1_import::g1_stats();
                     }
                     $queuelen = 100;
                     $thisstart = $task->get('last_id', 0);
                     $nextstart = $thisstart + $queuelen;
                     $task->set('last_id', $nextstart);
                     $task->set('queue', $queue = array_splice(g1_import::$queued_items, $thisstart, $queuelen));
                 }
                 $log_message = g1_import::import_item($queue);
                 if ($log_message) {
                     $task->log($log_message);
                 }
                 $task->status = t('Importing photos (%count of %total)', array('count' => $done['items'] + 1, 'total' => $stats['items']));
                 break;
             case 'comments':
                 if (empty($queue)) {
                     if (count(g1_import::$queued_comments) == 0) {
                         g1_import::g1_stats();
                     }
                     $queuelen = 100;
                     $thisstart = $task->get('last_id', 0);
                     $nextstart = $thisstart + $queuelen;
                     $task->set('last_id', $nextstart);
                     $task->set('queue', $queue = array_splice(g1_import::$queued_comments, $thisstart, $queuelen));
                 }
                 $log_message = g1_import::import_comment($queue);
                 if ($log_message) {
                     $task->log($log_message);
                 }
                 $task->status = t('Importing comments (%count of %total)', array('count' => $done['comments'] + 1, 'total' => $stats['comments']));
                 break;
             case 'highlights':
                 if (empty($queue)) {
                     if (count(g1_import::$queued_highlights) == 0) {
                         g1_import::g1_stats();
                     }
                     $queuelen = 100;
                     $thisstart = $task->get('last_id', 0);
                     $nextstart = $thisstart + $queuelen;
                     $task->set('last_id', $nextstart);
                     $task->set('queue', $queue = array_splice(g1_import::$queued_highlights, $thisstart, $queuelen));
                 }
                 $log_message = g1_import::set_album_highlight($queue);
                 if ($log_message) {
                     $task->log($log_message);
                 }
                 $task->status = t('Album highlights (%count of %total)', array('count' => $done['highlights'] + 1, 'total' => $stats['highlights']));
                 break;
             case 'fix':
                 if (empty($queue)) {
                     if (count(g1_import::$albums_flat) == 0) {
                         g1_import::g1_stats();
                     }
                     $task->set('queue', $queue = 'dummy');
                 }
                 $log_message = g1_import::hotfix_all();
                 if ($log_message) {
                     $task->log($log_message);
                 }
                 $task->status = t('Final Hotfixing (%count of %total)', array('count' => $done['fix'] + 1, 'total' => $stats['fix']));
                 break;
             case 'done':
                 $task->status = t('Import complete');
                 $task->done = true;
                 $task->state = 'success';
                 break;
         }
         if (!$task->done) {
             $done[$modes[$mode]]++;
             $completed++;
         }
     }
     $task->percent_complete = 100 * ($completed / $total);
     $task->set('completed', $completed);
     $task->set('mode', $mode);
     $task->set('queue', $queue);
     $task->set('done', $done);
 }