Merge "Add drush import-static-pages command"
This commit is contained in:
commit
1e15f606ba
|
@ -98,6 +98,7 @@ dependencies[] = commons_location
|
||||||
dependencies[] = commons_media
|
dependencies[] = commons_media
|
||||||
dependencies[] = commons_misc
|
dependencies[] = commons_misc
|
||||||
dependencies[] = commons_notify
|
dependencies[] = commons_notify
|
||||||
|
dependencies[] = commons_pages
|
||||||
dependencies[] = commons_polls
|
dependencies[] = commons_polls
|
||||||
dependencies[] = commons_posts
|
dependencies[] = commons_posts
|
||||||
dependencies[] = commons_profile_base
|
dependencies[] = commons_profile_base
|
||||||
|
|
|
@ -5,6 +5,11 @@
|
||||||
* jekyll like yaml headers.
|
* jekyll like yaml headers.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base class for all exceptions thrown by FeedsMarkdownParse
|
||||||
|
*/
|
||||||
|
class FeedsMarkdownException extends Exception {}
|
||||||
|
|
||||||
class FeedsMarkdownParser extends FeedsParser {
|
class FeedsMarkdownParser extends FeedsParser {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -15,7 +20,15 @@ class FeedsMarkdownParser extends FeedsParser {
|
||||||
public function parse(FeedsSource $source, FeedsFetcherResult $fetcher_result) {
|
public function parse(FeedsSource $source, FeedsFetcherResult $fetcher_result) {
|
||||||
$result = new FeedsParserResult();
|
$result = new FeedsParserResult();
|
||||||
$raw = $fetcher_result->getRaw();
|
$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');
|
$mandatory_fields = array('title', 'body');
|
||||||
$optional_fields = array('path', 'published');
|
$optional_fields = array('path', 'published');
|
||||||
$item = array();
|
$item = array();
|
||||||
|
@ -100,7 +113,7 @@ class FeedsMarkdownParser extends FeedsParser {
|
||||||
// parse header marker, we except --- here
|
// parse header marker, we except --- here
|
||||||
$line = fgets($fp);
|
$line = fgets($fp);
|
||||||
if ($line != "---\n") {
|
if ($line != "---\n") {
|
||||||
throw new Exception('Missing header mark');
|
throw new FeedsMarkdownException('Missing header mark');
|
||||||
}
|
}
|
||||||
// process content
|
// process content
|
||||||
$line = fgets($fp);
|
$line = fgets($fp);
|
||||||
|
|
|
@ -27,6 +27,11 @@ function groups_feeds_drush_command() {
|
||||||
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
|
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
|
||||||
'arguments' => array(),
|
'arguments' => array(),
|
||||||
);
|
);
|
||||||
|
$items['import-static-pages'] = array(
|
||||||
|
'description' => 'Import static pages.',
|
||||||
|
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
|
||||||
|
'arguments' => array(),
|
||||||
|
);
|
||||||
return $items;
|
return $items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,4 +55,26 @@ function drush_groups_feeds_import_meetup_events() {
|
||||||
echo 'Failed to import feed: '.$url."\n";
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,8 +1,9 @@
|
||||||
name = Groups feeds
|
name = Groups feeds
|
||||||
description = Community portal Feeds module extension
|
description = Community portal Feeds module extension
|
||||||
core = 7.x
|
core = 7.x
|
||||||
package = groups
|
package = Groups - Building Blocks
|
||||||
version = 7.x-1.0
|
version = 7.x-1.0
|
||||||
project = groups_feeds
|
project = groups_feeds
|
||||||
|
|
||||||
dependencies[] = feeds
|
dependencies[] = feeds
|
||||||
|
dependencies[] = commons_pages
|
Loading…
Reference in New Issue