Exemple #1
0
function createDb($connection)
{
    //Drop all tables
    $sql1 = 'DROP TABLE IF EXISTS story;';
    $sql2 = 'DROP TABLE IF EXISTS tasks;';
    $sql3 = 'DROP TABLE IF EXISTS comments;';
    $sql4 = 'DROP TABLE IF EXISTS history;';
    $sql5 = 'DROP TABLE IF EXISTS epics;';
    $sql6 = 'DROP TABLE IF EXISTS labels;';
    $sql7 = 'DROP TABLE IF EXISTS attachments;';
    $connection->query($sql1);
    $connection->query($sql2);
    $connection->query($sql3);
    $connection->query($sql4);
    $connection->query($sql5);
    $connection->query($sql6);
    $connection->query($sql7);
    //Create tables
    createTableStory($connection);
    createTableTasks($connection);
    createTableComments($connection);
    createTableHistory($connection);
    createTableEpics($connection);
    createTableLabels($connection);
    createTableAttachments($connection);
    return true;
}
function createTables($user, $password, $server, $DBname)
{
    $dbh = mysql_connect($server, $user, $password) or die('WebChess cannot connect to the database.
              Please check the database settings you provided.<br>');
    mysql_select_db($DBname);
    //$logMsg .= "Probing for table games..\n";
    echo "Probing for table games..<br>";
    if (!tableExists("games")) {
        //$logMsg .= "Creating table games..\n";
        echo "Creating table games..<br>";
        $result = createTableGames();
        showMessage($result);
    } else {
        showProbingMessage(true);
    }
    //$logMsg .= "Probing for table history..\n";
    echo "Probing for table history..<br>";
    if (!tableExists("history")) {
        //$logMsg .= "Creating table history..\n";
        echo "Creating table history..<br>";
        $result = createTableHistory();
        showMessage($result);
    } else {
        showProbingMessage(true);
    }
    //$logMsg .= "Probing for table messages..\n";
    echo "Probing for table messages..<br>";
    if (!tableExists("messages")) {
        //$logMsg .= "Creating table messages..\n";
        echo "Creating table messages..<br>";
        $result = createTableMessages();
        showMessage($result);
    } else {
        showProbingMessage(true);
    }
    //$logMsg .= "Probing for table pieces..\n";
    echo "Probing for table pieces..<br>";
    if (!tableExists("pieces")) {
        //$logMsg .= "Creating table pieces..\n";
        echo "Creating table pieces..<br>";
        $result = createTablePieces();
        showMessage($result);
    } else {
        showProbingMessage(true);
    }
    // ToDo: consider checking for fields named "pCol" and "pRow" in "pieces" table (n8chessnet) or updating to pCol and pRow
    //$logMsg .= "Probing for table players..\n";
    echo "Probing for table players..<br>";
    if (!tableExists("players")) {
        //$logMsg .= "Creating table players..\n";
        echo "Creating table players..<br>";
        $result = createTablePlayers();
        showMessage($result);
    } else {
        //$logMsg .= "Table players exists. Checking if table players has field lastAccess..\n";
        echo "Table players exists. Checking if table players has the lastAccess field..<br>";
        // Check if field "lastAccess" exists..
        if (!tablePlayersHasLastAccessField()) {
            // if false: update by calling addLastAccessFieldToPlayersTable()
            //$logMsg .= "Adding lastAccess field..\n";
            echo "Adding lastAccess field..<br>";
            addLastAccessFieldToPlayersTable();
        } else {
            echo "Field lastAccess exists. Nothing done.<br>";
        }
    }
    //$logMsg .= "Probing for table preferences..\n";
    echo "Probing for table preferences..<br>";
    if (!tableExists("preferences")) {
        //$logMsg .= "Creating table preferences..\n";
        echo "Creating table preferences..<br>";
        $result = createTablePreferences();
        showMessage($result);
    } else {
        showProbingMessage(true);
    }
    //$logMsg .= "Probing for table communication..\n";
    echo "Probing for table communication..<br>";
    if (!tableExists("communication")) {
        //$logMsg .= "Creating table communication..\n";
        echo "Creating table communication..<br>";
        $result = createTableCommunication();
        showMessage($result);
        //$logMsg .= "Inserting message to communication table..\n";
        echo "Inserting message to communication table....<br>";
        $result = insertSampleFieldIntoCommunications();
        if ($result == 1) {
            echo "message inserted correctly.";
        } else {
            echo "<b>ERROR</b>! The field message was not inserted correctly!";
        }
    } else {
        showProbingMessage(true);
    }
    //ToDo: Make logfile work properly.
    //Without the proper permision, php won't be able to write any file.
    //In many free web hosting providers it won't be possible to allow proper
    //write permision, so it is not advisable to use this. It is needed a workaround.
    //Following code comented until this workaround is found.
    //echo ereg_replace("\n","<br />",$logMsg);
    //writeLogFile($logMsg);
    mysql_query("quit");
}