FeedImportController.php in Feed Import 8
File
src/Controller/FeedImportController.php
View source
<?php
namespace Drupal\feed_import\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Link;
use Drupal\feed_import_base\FeedImport;
class FeedImportController extends ControllerBase {
function exportFeed($fid) {
$feed = FeedImport::loadFeed($fid);
unset($feed->id, $feed->last_run, $feed->last_run_duration, $feed->last_run_items, $feed->name, $feed->machine_name, $feed->cron_import);
$opt = 0;
if (defined('JSON_PRETTY_PRINT')) {
$opt |= JSON_PRETTY_PRINT;
}
if (defined('JSON_UNESCAPED_SLASHES')) {
$opt |= JSON_UNESCAPED_SLASHES;
}
$feed = json_encode($feed, $opt);
return array(
'#theme' => 'textarea',
'#value' => $feed,
'#rows' => 15,
);
}
function processFeed($fid) {
$feed = FeedImport::loadFeed($fid);
$status = _feed_import_base_process_feed($feed, TRUE);
switch ($status) {
case FeedImport::FEED_OK:
drupal_set_message(t('Feed @name processed!', array(
'@name' => $feed->name,
)));
break;
case FeedImport::FEED_OVERLAP_ERR:
drupal_set_message(t('Cannot process feed because another one is running!'), 'error');
break;
case FeedImport::FEED_CONFIG_ERR:
drupal_set_message(t('Cannot process feed because source is misconfigured!'), 'error');
break;
case FeedImport::FEED_SOURCE_ERR:
drupal_set_message(t('Cannot process feed because there is a source error!'), 'error');
drupal_set_message(t('All items were rescheduled due to delete protection!'), 'warning');
break;
case FeedImport::FEED_ITEMS_ERR:
drupal_set_message(t('Feed @name processed!', array(
'@name' => $feed->name,
)));
drupal_set_message(t('All items were rescheduled due to delete protection!'), 'warning');
break;
}
return $this
->redirect('feed_import.admin');
}
public function getTitle($feed_importer) {
if ($feed_importer) {
return $feed_importer
->label();
}
return 'Feed Import';
}
}