This repository has been archived by the owner on Feb 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NEW: Added dev/tasks/ExternalContentImportContentTask for CLI content…
… import
- Loading branch information
Sam Minnee
committed
Jul 21, 2014
1 parent
1b6a705
commit 3344f73
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |