Skip to content
This repository has been archived by the owner on Feb 27, 2024. It is now read-only.

Commit

Permalink
NEW: Added dev/tasks/ExternalContentImportContentTask for CLI content…
Browse files Browse the repository at this point in the history
… import
  • Loading branch information
Sam Minnee committed Jul 21, 2014
1 parent 1b6a705 commit 3344f73
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
10 changes: 10 additions & 0 deletions code/StaticSitePageTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
class StaticSitePageTransformer implements ExternalContentTransformer {

public function transform($item, $parentObject, $duplicateStrategy) {
if(Director::is_cli()) {
Debug::message("Parent: #$parentObject->ID, $parentObject->Title");
Debug::message($item->AbsoluteURL);
}

// Sleep for 100ms to reduce load on the remote server
usleep(100*1000);

Expand Down Expand Up @@ -55,6 +60,11 @@ public function transform($item, $parentObject, $duplicateStrategy) {

$page->write();

if(Director::is_cli()) {
Debug::message("#$page->Title");
Debug::message("#$page->ID child of #$page->ID");
}

return new TransformResult($page, $item->stageChildren());
}

Expand Down
37 changes: 37 additions & 0 deletions code/tasks/ExternalContentImportContentTask.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/**
* External content - run import as a build task, importing content into a new container
*/
class ExternalContentImportContentTask extends BuildTask {

function run($request) {
$id = $request->getVar('ID');
if((!is_numeric($id) && !preg_match('/^[0-9]+_[0-9]+$/', $id)) || !$id) {
echo "<p>Specify ?ID=(number) or ?ID=(ID)_(Code)</p>\n";
return;
}

$includeSelected = false;
$includeChildren = true;
$duplicates = 'Duplicate';
$selected = $id;

$target = new Page;
$target->Title = "Import on " . date('Y-m-d H:i:s');
$target->write();
$targetType = 'SiteTree';

$from = ExternalContent::getDataObjectFor($selected);
if ($from instanceof ExternalContentSource) {
$selected = false;
}

$importer = null;
$importer = $from->getContentImporter($targetType);

if ($importer) {
$importer->import($from, $target, $includeSelected, $includeChildren, $duplicates);
}
}
}

0 comments on commit 3344f73

Please sign in to comment.