function export_identity(&$a, $channel_hash)
{
    if ($channel_hash == '') {
        json_error_die(422, 'Unprocessable Entity', 'Must supply channel_hash parameter.');
    }
    json_return_and_die(identity_basic_export(get_channel_id($channel_hash), $_REQUEST['posts'] ? intval($_REQUEST['posts']) : 0));
}
function get_channel_by_hash($channel_hash)
{
    $c = q("select * from channel where channel_hash = '%s' LIMIT 1", dbesc($channel_hash));
    if (!$c) {
        json_error_die(404, 'Not Found', 'No such channel ' . $channel_hash);
    }
    return $c[0];
}
function migrator_update_directory(&$a, $channel_hash)
{
    $channel_id = get_channel_id($channel_hash);
    if (!$channel_id) {
        json_error_die(404, 'Not Found', 'No such channel ' . $channel_hash);
    }
    proc_run('php', 'include/notifier.php', 'location', $channel_id);
    proc_run('php', 'include/directory.php', $channel_id);
    json_return_and_die(array("status" => 'OK', 'channel_hash' => $channel_hash, 'channel_id' => $channel_id));
}
Esempio n. 4
0
function migrator_init(&$a)
{
    $x = argc();
    if ($x > 1) {
        api_login($a);
        switch (argv(1)) {
            case "version":
                json_return_and_die(array("status" => "OK", 'platform' => PLATFORM_NAME, 'platform_version' => RED_VERSION, 'zot_version' => ZOT_REVISION, 'db_version' => DB_UPDATE_VERSION, 'migrator_version' => MIGRATOR_VERSION));
                break;
            case "import":
                if (PLATFORM_NAME == "redmatrix") {
                    json_error_die(400, 'Bad Request', 'Cannot import to Redmatrix, only to Hubzilla.');
                }
                switch (argv(2)) {
                    case 'account':
                        migrator_import_account($a);
                        break;
                    case 'identity':
                        migrator_import_identity($a, argv(3));
                        break;
                    case 'items':
                        migrator_import_items($a, argv(3));
                        break;
                    case 'directory':
                        migrator_update_directory($a, argv(3));
                        break;
                    default:
                        json_error_die(404, 'Not Found', 'No such endpoint');
                        break;
                }
            case "export":
                switch (argv(2)) {
                    case "users":
                        export_users($a);
                        break;
                    case "channel_hashes":
                        export_channel_hashes($a, argv(3));
                        break;
                    case "identity":
                        export_identity($a, argv(3));
                        break;
                    case "first_post":
                        first_post($a, argv(3));
                        break;
                    case "items":
                        export_items($a, argv(3), argv(4), argv(5));
                        break;
                    default:
                        json_error_die(404, 'Not Found', 'No such endpoint');
                        break;
                }
                break;
            default:
                json_error_die(404, 'Not Found', 'No such endpoint');
                break;
        }
    }
}