Merge "Add drush import-static-pages command"

This commit is contained in:
Jenkins 2014-06-30 13:08:45 +00:00 committed by Gerrit Code Review
commit 1e15f606ba
4 changed files with 46 additions and 4 deletions

View File

@ -98,6 +98,7 @@ dependencies[] = commons_location
dependencies[] = commons_media
dependencies[] = commons_misc
dependencies[] = commons_notify
dependencies[] = commons_pages
dependencies[] = commons_polls
dependencies[] = commons_posts
dependencies[] = commons_profile_base

View File

@ -5,6 +5,11 @@
* jekyll like yaml headers.
*/
/**
* Base class for all exceptions thrown by FeedsMarkdownParse
*/
class FeedsMarkdownException extends Exception {}
class FeedsMarkdownParser extends FeedsParser {
/**
@ -15,7 +20,15 @@ class FeedsMarkdownParser extends FeedsParser {
public function parse(FeedsSource $source, FeedsFetcherResult $fetcher_result) {
$result = new FeedsParserResult();
$raw = $fetcher_result->getRaw();
$markdown = $this->parseMarkdown($raw);
if ($fetcher_result instanceof FeedsFileFetcherResult) {
var_dump($fetcher_result);
}
try {
$markdown = $this->parseMarkdown($raw);
} catch (FeedsMarkdownException $e) {
// catch invalid markdown formats here
return $result;
}
$mandatory_fields = array('title', 'body');
$optional_fields = array('path', 'published');
$item = array();
@ -100,7 +113,7 @@ class FeedsMarkdownParser extends FeedsParser {
// parse header marker, we except --- here
$line = fgets($fp);
if ($line != "---\n") {
throw new Exception('Missing header mark');
throw new FeedsMarkdownException('Missing header mark');
}
// process content
$line = fgets($fp);

View File

@ -27,6 +27,11 @@ function groups_feeds_drush_command() {
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
'arguments' => array(),
);
$items['import-static-pages'] = array(
'description' => 'Import static pages.',
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
'arguments' => array(),
);
return $items;
}
@ -50,4 +55,26 @@ function drush_groups_feeds_import_meetup_events() {
echo 'Failed to import feed: '.$url."\n";
}
}
}
/**
* Trigger static pages import.
*/
function drush_groups_feeds_import_static_pages() {
$feedSource = feeds_source('static_page_import');
$config = $feedSource->getConfig();
$directory = variable_get('groups_feeds_markdown_directory', NULL);
if (empty($directory)) {
watchdog('drush_groups_feeds', 'Variable groups_feeds_markdown_directory missing.', array(), WATCHDOG_ERROR);
return FALSE;
}
$config['feeds_fetcher_directory_fetcher']['source'] = $directory;
$config['feeds_fetcher_directory_fetcher']['feed_files_fetched'] = array();
$feedSource->setConfig($config);
try {
while (FEEDS_BATCH_COMPLETE != $feedSource->import());
$feedSource->log('import', 'Import static page: !source', array('!directory' => $directory), WATCHDOG_INFO);
} catch (Exception $e) {
watchdog_exception('Groups Feeds', $e);
}
}

View File

@ -1,8 +1,9 @@
name = Groups feeds
description = Community portal Feeds module extension
core = 7.x
package = groups
package = Groups - Building Blocks
version = 7.x-1.0
project = groups_feeds
dependencies[] = feeds
dependencies[] = feeds
dependencies[] = commons_pages