/**
 * @return array
 */
function dav_upgrade_tables()
{
    $ver = dav_check_tables();
    if (!in_array($ver, array(1, 2))) {
        return array("Unknown error");
    }
    $stms = dav_get_update_statements($ver);
    $errors = array();
    global $db;
    foreach ($stms as $st) {
        // @TODO Friendica-dependent
        $db->q($st);
        if ($db->error) {
            $errors[] = $db->error;
        }
    }
    return $errors;
}
Exemplo n.º 2
0
/**
 * @param App $a
 * @param string $o
 */
function dav_plugin_admin(&$a, &$o)
{
    dav_include_files();
    require_once __DIR__ . "/database-init.inc.php";
    $dbstatus = dav_check_tables();
    $o = '<input type="hidden" name="form_security_token" value="' . get_form_security_token("dav_admin_save") . '">';
    $o .= '<i>' . t("No system-wide settings yet.") . '</i><br><br>';
    $o .= '<h3>' . t('Database status') . '</h3>';
    switch ($dbstatus) {
        case 0:
            $o .= t('Installed');
            break;
        case 1:
        case 2:
            $o .= "<strong>" . t('Upgrade needed') . "</strong><br>" . t("Please back up all calendar data (the tables beginning with dav_*) before proceeding. While all calendar events <i>should</i> be converted to the new database structure, it's always safe to have a backup. Below, you can have a look at the database-queries that will be made when pressing the 'update'-button.") . "<br><br><input type='submit' name='upgrade' value='" . t('Upgrade') . "'>";
            break;
        case -1:
            $o .= t('Not installed') . "<br><br><input type='submit' name='install' value='" . t('Install') . "'>";
            break;
        case -2:
        default:
            $o .= t('Unknown') . "<br><br>" . t("Something really went wrong. I cannot recover from this state automatically, sorry. Please go to the database backend, back up the data, and delete all tables beginning with 'dav_' manually. Afterwards, this installation routine should be able to reinitialize the tables automatically.");
            break;
    }
    $o .= "<br><br>";
    $o .= "<h3>" . t("Troubleshooting") . "</h3>";
    $o .= "<h4>" . t("Manual creation of the database tables:") . "</h4>";
    $o .= "<a href='#' onClick='\$(\"#sqlstatements\").show(); return false;'>" . t("Show SQL-statements") . "</a><blockquote style='display: none;' id='sqlstatements'><pre>";
    switch ($dbstatus) {
        case 1:
        case 2:
            $tables = dav_get_update_statements($dbstatus);
            foreach ($tables as $t) {
                $o .= escape_tags($t . ";\n\n");
            }
            break;
        default:
            $tables = dav_get_create_statements();
            foreach ($tables as $t) {
                $o .= escape_tags($t . ";\n\n");
            }
            break;
    }
    $o .= "</pre></blockquote>";
}