Skip to content

Instantly share code, notes, and snippets.

@bartjkdp
Created December 22, 2015 11:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bartjkdp/cb4581d91aea43ec2963 to your computer and use it in GitHub Desktop.
Save bartjkdp/cb4581d91aea43ec2963 to your computer and use it in GitHub Desktop.
<?php
ini_set('display_errors', 1);
$_SERVER["HTTP_HOST"] = "pleio.dev";
$_SERVER["HTTPS"] = false;
require_once(dirname(__FILE__) . "/engine/start.php");
$options = array(
'type' => 'object',
'limit' => false,
'subtypes' => array('file','events','blog','bookmark','page_top','page','event','question'),
'access_ids' => array(ACCESS_PUBLIC, ACCESS_LOGGED_IN)
);
$file = fopen('export.json', 'w');
$i = 0;
$subtypes = array();
foreach (array('file','events','blog','bookmark','page_top','page','event','question') as $subtype) {
$subtype = get_subtype_id('object', $subtype);
if ($subtype) {
$subtypes[] = $subtype;
}
}
$sql = "SELECT guid FROM elgg_entities WHERE type='object' AND subtype IN (" . implode(",", $subtypes) . ") AND access_id IN (1,2)";
$rows = get_data($sql);
if (!is_dir("file")) {
mkdir("file");
}
foreach ($rows as $row) {
$entity = get_entity($row->guid);
if (!$entity) {
continue;
}
$subtype = $entity->getSubtype();
$json = array(
'type' => $entity->type,
'subtype' => $subtype,
'title' => $entity->title,
'description' => $entity->description,
'access_id' => $entity->access_id
);
if ($subtype == "file") {
$json['filename'] = $entity->getFilename();
}
if (file_exists($entity->getFilenameOnFilestore())) {
copy($entity->getFilenameOnFilestore(), $entity->getFilename());
}
fwrite($file, json_encode($json) . PHP_EOL);
$i++;
if ($i === 1000) {
break;
}
}
fclose($file);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment