Skip to content

Export page aliases and external links #111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
use Concrete\Core\Application\EditResponse;
use Concrete\Core\File\File;
use Concrete\Core\Page\Controller\DashboardSitePageController;
use Concrete\Package\MigrationTool\Page\Controller\DashboardPageController;
use Doctrine\Common\Collections\ArrayCollection;
use PortlandLabs\Concrete5\MigrationTool\Entity\Export\Batch;
use PortlandLabs\Concrete5\MigrationTool\Entity\Export\ObjectCollection;
Expand Down Expand Up @@ -81,16 +80,34 @@ public function export_batch($id = null)
{
$r = $this->entityManager->getRepository('\PortlandLabs\Concrete5\MigrationTool\Entity\Export\Batch');
$batch = $r->findOneById($id);
if (is_object($batch)) {
$exporter = new Exporter($batch);
$files = $exporter->getReferencedFiles();
$this->set('files', $files);
$this->set('batch', $batch);
$this->set('pageTitle', t('Export Batch'));
$this->render('/dashboard/system/migration/finalize_export_batch');
} else {
$this->view();
if ($batch === null) {
return $this->view();
}
$this->set('batch', $batch);
$exporter = new Exporter($batch);
$files = $exporter->getReferencedFiles();
$this->set('files', $files);
$sx = $exporter->getElement();
$xml = $sx->saveXML();
try {
$doc = new \DOMDocument();
$doc->preserveWhiteSpace = false;
$doc->formatOutput = true;
$flags = 0 | (defined('LIBXML_BIGLINES') ? LIBXML_BIGLINES : 0);
$restore = libxml_use_internal_errors(true);
try {
if ($doc->loadXML($xml, $flags) !== false && !libxml_get_errors()) {
$xml = $doc->saveXML();
}
} finally {
libxml_use_internal_errors($restore);
}
} catch (\Exception $_) {
} catch (\Throwable $_) {
}
$this->set('xml', $xml);
$this->set('pageTitle', t('Export Batch'));
$this->render('/dashboard/system/migration/finalize_export_batch');
}

public function download_files()
Expand Down Expand Up @@ -152,25 +169,6 @@ public function download_files()
exit;
}

public function export_batch_xml($id = null)
{
$r = $this->entityManager->getRepository('\PortlandLabs\Concrete5\MigrationTool\Entity\Export\Batch');
$batch = $r->findOneById($id);
if (is_object($batch)) {
$exporter = new Exporter($batch);
if ($this->request->request->get('download')) {
header('Content-disposition: attachment; filename="export.xml"');
header('Content-type: "text/xml"; charset="utf8"');
} else {
header('Content-type: text/xml');
}
echo $exporter->getElement()->asXML();
exit;
} else {
$this->view();
}
}

public function add_items_to_batch()
{
if (!$this->token->validate('add_items_to_batch')) {
Expand Down
37 changes: 36 additions & 1 deletion packages/migration_tool/elements/export/search/page.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
foreach ($list as $type) {
$pagetypes[$type->getPageTypeID()] = $type->getPageTypeDisplayName();
}
// Let's check if we have a class that has been introduced in the core when we added support for exporting page aliases and external links
if (class_exists('Concrete\Core\Backup\ContentImporter\Exception\MissingPageAtPathException')) {
$whyNoAdditionalTypes = '';
} else {
$whyNoAdditionalTypes = t("Your version of concrete5 doesn't support exporting external links and aliases: please upgrade to a newer version.");
}
?>
<div class="form-group">
<label class="control-label"><?=t('Keywords')?></label>
Expand All @@ -34,6 +40,35 @@

<div class="form-group">
<div class="checkbox">
<label> <?php echo $form->checkbox('includeSystemPages', 1, $includeSystemPages); ?><?=t('Include System Pages'); ?></label>
<label>
<?= $form->checkbox('includeSystemPages', 1, !empty($includeSystemPages)) ?>
<?= t('Include System Pages') ?>
</label>
</div>
<div class="checkbox">
<label>
<?= $form->checkbox('includeExternalLinks', 1, !empty($includeExternalLinks), $whyNoAdditionalTypes === '' ? [] : ['disabled' => 'disabled']) ?>
<?= t('Include External Links') ?>
<?php
if ($whyNoAdditionalTypes !== '') {
?>
<i class="fa fa-ban text-warning launch-tooltip" title="<?= h($whyNoAdditionalTypes) ?>"></i>
<?php
}
?>
</label>
</div>
<div class="checkbox">
<label>
<?= $form->checkbox('includeAliases', 1, !empty($includeAliases), $whyNoAdditionalTypes === '' ? [] : ['disabled' => 'disabled']) ?>
<?=t('Include Page Aliases') ?>
<?php
if ($whyNoAdditionalTypes !== '') {
?>
<i class="fa fa-ban text-warning launch-tooltip" title="<?= h($whyNoAdditionalTypes) ?>"></i>
<?php
}
?>
</label>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
<?php defined('C5_EXECUTE') or die("Access Denied."); ?>
<?php
defined('C5_EXECUTE') or die('Access Denied.');

/**
* @var Concrete\Core\Page\View\PageView $view
* @var Concrete\Core\Validation\CSRF\Token $token
* @var Concrete\Core\Form\Service\Form $form
*
* @var PortlandLabs\Concrete5\MigrationTool\Entity\Export\Batch $batch
* @var Concrete\Core\Entity\File\File[] $files
* @var string $xml
*/

?>
<div class="ccm-dashboard-header-buttons">
<a href="<?=$view->action('view_batch', $batch->getID())?>" class="btn btn-default"><i class="fa fa-angle-double-left"></i> <?=t('Back to Batch')?></a>
<a href="<?= h($view->action('view_batch', $batch->getID())) ?>" class="btn btn-default"><i class="fa fa-angle-double-left"></i> <?= t('Back to Batch') ?></a>
</div>

<?php if (count($files)) {
<?php
if ($files !== []) {
?>

<script type="text/javascript">
<script>
$(function() {
$('input[data-checkbox=select-all]').on('click', function() {
if ($(this).is(':checked')) {
Expand All @@ -27,48 +40,78 @@

});
</script>

<form method="post" action="<?=$view->action('download_files')?>">
<input type="hidden" name="id" value="<?=$batch->getID()?>">
<?=Loader::helper('validation/token')->output('download_files')?>
<button style="float: right" disabled class="btn btn-xs btn-default" data-action="download-files" type="submit"><?=t('Download Files')?></button>
<h3><?=t('Files')?></h3>

<form method="POST" action="<?= h($view->action('download_files')) ?>">
<?php $token->output('download_files') ?>
<input type="hidden" name="id" value="<?= $batch->getID() ?>" />
<button style="float: right" disabled class="btn btn-xs btn-default" data-action="download-files" type="submit"><?= t('Download Files') ?></button>
<h3><?= t('Files') ?></h3>
<table class="table table-striped zebra-striped">
<thead>
<tr>
<th><input type="checkbox" data-checkbox="select-all"></th>
<th><?=t('ID')?></th>
<th style="width: 100%"><?=t('Filename')?></th>
</tr>
</thead>
<tbody>
<?php foreach ($files as $file) {
?>
<tr>
<td><input type="checkbox" data-checkbox="batch-file" name="batchFileID[]" value="<?=$file->getFileID()?>"></td>
<td><?=$file->getFileID()?></td>
<td><?=$file->getFileName()?></td>
<th><input type="checkbox" data-checkbox="select-all"></th>
<th><?= t('ID') ?></th>
<th style="width: 100%"><?= t('Filename') ?></th>
</tr>
<?php
}
?>
</thead>
<tbody>
<?php
foreach ($files as $file) {
?>
<tr>
<td><input type="checkbox" data-checkbox="batch-file" name="batchFileID[]" value="<?= $file->getFileID() ?>"></td>
<td><?= $file->getFileID() ?></td>
<td><?= h($file->getFileName()) ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
</form>
<?php
<?php
} else {
?>
<h3><?=t('Files')?></h3>
<p><?=t('No referenced files found.')?></p>
<?php
} ?>
<h3><?= t('Files') ?></h3>
<p><?= t('No referenced files found.') ?></p>
<?php
}
?>
<h3><?= t('Content XML') ?></h3>
<div class="btn-group">
<button type="button" id="mt-export-xml-view" class="btn btn-default"><?= t('View XML') ?></button>
<button type="button" id="mt-export-xml-download" class="btn btn-default"><?= t('Download XML') ?></button>
</div>
<script>
addEventListener('DOMContentLoaded', () => {

const XML = <?= json_encode($xml) ?>;
function sendXML(download)
{
const blob = new Blob([XML], {type: 'application/xml; charset=utf-8'});
const url = URL.createObjectURL(blob);
if (download) {
const a = document.createElement('a');
a.href = url;
a.download = 'export.xml';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
} else {
window.open(url, '_blank');
setTimeout(() => URL.revokeObjectURL(url), 15000);
}
}

document.querySelector('#mt-export-xml-view').addEventListener('click', (e) => {
e.preventDefault();
sendXML(false);
});

<h3><?=t('Content XML')?></h3>
<form method="post" action="<?=$view->action('export_batch_xml', $batch->getID())?>">
<div class="btn-group">
<button type="submit" name="view" value="1" class="btn btn-default"><?=t('View XML')?></button>
<button type="submit" name="download" value="1" class="btn btn-default"><?=t('Download XML')?></button>
</div>
</form>
document.querySelector('#mt-export-xml-download').addEventListener('click', (e) => {
e.preventDefault();
sendXML(true);
});

});
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@

class Exporter
{
/**
* @var \PortlandLabs\Concrete5\MigrationTool\Entity\Export\Batch
*/
protected $batch;
protected $built = false;

/**
* @var \SimpleXMLElement|null
*/
protected $element;

public function __construct(Batch $batch)
Expand All @@ -27,9 +33,12 @@ protected function build()
}
}

/**
* @return \SimpleXMLElement
*/
public function getElement()
{
if (!$this->built) {
if (!$this->element) {
$this->build();
}

Expand All @@ -38,6 +47,8 @@ public function getElement()

/**
* Loops through all pages and returns files referenced.
*
* @return \Concrete\Core\Entity\File\File[]
*/
public function getReferencedFiles()
{
Expand Down
Loading