Skip to content

Instantly share code, notes, and snippets.

@bartjkdp
Created December 22, 2015 11:44
Show Gist options
  • Save bartjkdp/6b5ed6115ecdf39bb97b to your computer and use it in GitHub Desktop.
Save bartjkdp/6b5ed6115ecdf39bb97b 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");
$user = get_user_by_username('admin');
login($user);
$file = fopen('export.json', 'r');
while (($line = fgets($file)) !== false) {
$json = json_decode($line);
if ($json->subtype == 'file') {
$object = new FilePluginFile();
} else {
$object = new ElggObject();
$object->subtype = get_subtype_id('object', $json['subtype']);
}
$object->title = $json->title;
$object->description = $json->description;
$object->access_id = $json->access_id;
if ($json->subtype == 'file') {
$object->setFilename($json->filename);
$object->originalfilename = $json->filename;
$object->setMimeType(mime_content_type($json->filename));
$object->simpletype = file_get_simple_type($mime_type);
// make sure filepath exists
$object->open("write");
$object->close();
copy($json->filename, $object->getFilenameOnFilestore());
}
$object->save();
}
fclose($file);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment