예제 #1
0
function update_product($prodInfo)
{
    if (!isset($prodInfo['id'])) {
        throw new Exception("Product id required.");
    }
    $dbh = new PDOConnection();
    $query = "SELECT id,code,description,price,active,last_updated FROM products WHERE id = :id";
    $sth = $dbh->prepare($query);
    $id = $prodInfo['id'];
    $sth->bindParam(':id', $id, PDO::PARAM_INT);
    if (!$sth->execute()) {
        throw new Exception($sth->errorInfo()[2]);
    }
    if (!($oldValues = $sth->fetch())) {
        throw new Exception("Product id: '" . $id . "' not found!");
    }
    $query = "UPDATE products \n        SET code = :code, \n            description = :description, \n            price = :price, \n            class = :class, \n            active = :active \n        WHERE id = :id";
    $sth = $dbh->prepare($query);
    $code = isset($prodInfo['code']) ? $prodInfo['code'] : $oldValues['code'];
    $description = isset($prodInfo['description']) ? $prodInfo['description'] : $oldValues['description'];
    $price = isset($prodInfo['price']) ? $prodInfo['price'] : $oldValues['price'];
    $class = isset($prodInfo['class']) ? $prodInfo['class'] : $oldValues['class'];
    $active = isset($prodInfo['active']) ? $prodInfo['active'] : $oldValues['active'];
    $sth->bindParam(':id', $id, PDO::PARAM_INT);
    $sth->bindParam(':code', $code);
    $sth->bindParam(':description', $description);
    $sth->bindParam(':price', $price);
    $sth->bindParam(':class', $class, PDO::PARAM_INT);
    $sth->bindParam(':active', $active, PDO::PARAM_INT);
    $sth->execute();
    return true;
}
예제 #2
0
function add_product_class($info)
{
    $dbh = new PDOConnection();
    $product_id = isset($info['product_id']) ? $info['product_id'] : '';
    $unit_id = isset($info['unit_id']) ? $info['unit_id'] : '';
    $description = isset($info['description']) ? $info['description'] : '';
    if (!$product_id) {
        $product_code = isset($info['product_code']) ? $info['product_code'] : '';
        if (!$product_code) {
            throw new Exception("Product id or code required");
        }
        $query = "SELECT id FROM products WHERE code = :code";
        $sth = $dbh->prepare($query);
        $sth->bindParam(':code', $product_code);
        if (!$sth->execute()) {
            throw new Exception($sth->errorInfo()[2]);
        }
        $product_id = $sth->fetchColumn();
    }
    if (!$unit_id) {
        $unit_code = isset($info['product_code']) ? $info['unit_code'] : '';
        if (!$unit_code) {
            throw new Exception("Unit id or code required");
        }
        $query = "SELECT id FROM units WHERE code = :code";
        $sth = $dbh->prepare($query);
        $sth->bindParam(':code', $unit_code);
        if (!$sth->execute()) {
            throw new Exception($sth->errorInfo[2]);
        }
        $unit_id = $sth->fetchColumn();
    }
    $query = "SELECT id FROM product_unit WHERE product_id = :pid AND unit_id = :uid";
    $sth = $dbh->prepare($query);
    $sth->bindParam(':pid', $product_id, PDO::PARAM_INT);
    $sth->bindParam(':uid', $unit_id, PDO::PARAM_INT);
    $sth->execute();
    if ($sth->rowCount() > 0) {
        throw new Exception("Product/unit entry already exists.");
    }
    $query = "INSERT INTO product_unit(product_id,unit_id,description) VALUES(:pid,:uid,desc)";
    $sth = $dbh->prepare($query);
    $sth->bindParam(':pid', $product_id, PDO::PARAM_INT);
    $sth->bindParam(':uid', $unit_id, PDO::PARAM_INT);
    $sth->bindParam(':description', $description, PDO::PARAM_STR);
    if (!$sth->execute()) {
        throw new Exception($sth->errorInfo()[2]);
    }
    return true;
}
예제 #3
0
function get_addresses($values = NULL)
{
    if (!(isset($values['user_id']) || isset($values['customer_id']))) {
        throw new Exception("Must provide user_id or customer_id");
    }
    $query = "SELECT a.id address_id, a.last_updated, a.name, address1, address2, city, state, zipcode, type FROM addresses a \n            LEFT JOIN user_addresses ua ON a.id = ua.address_id \n            LEFT JOIN customer_addresses ca ON a.id = ca.address_id \n        WHERE (ua.user_id = :user_id or ca.customer_id = :customer_id) ";
    $execArray['user_id'] = isset($values['user_id']) ? $values['user_id'] : -1;
    $execArray['customer_id'] = isset($values['customer_id']) ? $values['customer_id'] : -1;
    if (isset($values['address_id'])) {
        $query .= " AND a.id = :address_id ";
        $execArray['address_id'] = (int) $values['address_id'];
    }
    if (isset($values['type'])) {
        $query .= " AND type = :type ";
        $execArray['type'] = (int) $values['type'];
    }
    $dbh = new PDOConnection();
    $sth = $dbh->prepare($query);
    if (!$sth->execute($execArray)) {
        throw new Exception($sth->errorInfo()[2]);
    }
    $addressArray = array();
    foreach ($sth->fetchAll(PDO::FETCH_ASSOC) as $row) {
        $addressArray[] = $row;
    }
    return $addressArray;
}
예제 #4
0
function update_address($addressInfo)
{
    if (!(isset($addressInfo['address_id']) && (isset($addressInfo['customer_id']) || isset($addressInfo['user_id'])))) {
        throw new Exception("ERROR: address_id and customer_id or user_id required");
    }
    $oldInfo = get_addresses($addressInfo)[0];
    //takes customer/user id and address id
    if (empty($oldInfo)) {
        throw new Exception("Could not find address id for customer or user.");
    }
    $addressInfo = array_replace($oldInfo, $addressInfo);
    $query = "UPDATE addresses SET name = :name, address1 = :address1, address2 = :address2, city = :city, state = :state, zipcode = :zipcode, type = :type WHERE id = :address_id";
    $dbh = new PDOConnection();
    $sth = $dbh->prepare($query);
    $sth->bindParam(':name', $addressInfo['name']);
    $sth->bindParam(':address1', $addressInfo['address1']);
    $sth->bindParam(':address2', $addressInfo['address2']);
    $sth->bindParam(':city', $addressInfo['city']);
    $sth->bindParam(':state', $addressInfo['state']);
    $sth->bindParam(':zipcode', $addressInfo['zipcode']);
    $sth->bindParam(':type', $addressInfo['type'], PDO::PARAM_INT);
    $sth->bindParam(':address_id', $addressInfo['address_id'], PDO::PARAM_INT);
    if (!$sth->execute()) {
        throw new Exception("ERROR: could not update address - " . $sth->errorInfo()[2]);
    }
    return $addressInfo;
}
예제 #5
0
function update_inventory($inventoryInfo)
{
    if (!isset($inventoryInfo['inventory'])) {
        throw new Exception('Must provide \'inventory\'');
    }
    $dbh = new PDOConnection();
    $query = "INSERT INTO inventory(\n                product_id, unit_id, quantity\n            )\n            VALUES(\n                :product_id, :unit_id, :quantity\n            )\n            ON DUPLICATE KEY UPDATE\n                quantity = :quantity";
    $product_id = -1;
    $unit_id = -1;
    $qantity = -1;
    $response = '';
    $sth = $dbh->prepare($query);
    $sth->bindParam(':product_id', $product_id, PDO::PARAM_INT);
    $sth->bindParam(':unit_id', $unit_id, PDO::PARAM_INT);
    $sth->bindParam(':quantity', $quantity);
    foreach ($inventoryInfo['inventory'] as $inventory) {
        $product_id = $inventory['product_id'];
        $unit_id = $inventory['unit_id'];
        $quantity = $inventory['quantity_id'];
        if (!$sth->execute()) {
            throw new Exception($sth->errorInfo()[2]);
        }
    }
    return true;
}
예제 #6
0
function update_unit($unitInfo)
{
    if (!isset($unitInfo['id'])) {
        throw new Exception("Product id required.");
    }
    $id = $unitInfo['id'];
    $dbh = new PDOConnection();
    $oldValues = get_units(array('id' => $id))[0];
    //returns array of units
    if (empty($oldValues)) {
        throw new Exception("Product id: '" . $id . "' not found!");
    }
    $query = "UPDATE units \n        SET code = :code, \n            description = :description, \n            active = :active\n        WHERE id = :id";
    $sth = $dbh->prepare($query);
    $code = isset($unitInfo['code']) ? $unitInfo['code'] : $oldValues['code'];
    $description = isset($unitInfo['description']) ? $unitInfo['description'] : $oldValues['description'];
    $active = isset($unitInfo['active']) ? $unitInfo['active'] : $oldValues['active'];
    $sth->bindParam(':id', $id, PDO::PARAM_INT);
    $sth->bindParam(':code', $code);
    $sth->bindParam(':description', $description);
    $sth->bindParam(':active', $active, PDO::PARAM_INT);
    if (!$sth->execute()) {
        throw new Exception($sth->errorInfo()[2]);
    }
    return true;
}
예제 #7
0
function add_product_class($classArray)
{
    $dbh = new PDOConnection();
    $code = $classArray['code'];
    $description = $classArray['description'];
    $query = "SELECT code FROM product_classes where code = :code";
    $sth = $dbh->prepare($query);
    $sth->bindParam(':code', $code, PDO::PARAM_STR);
    $sth->execute();
    if ($sth->rowCount() > 0) {
        throw new Exception("Class code exists");
    }
    $query = "INSERT INTO product_classes(description,code) VALUES(:description,:code)";
    $sth = $dbh->prepare($query);
    $sth->bindParam(':code', $code, PDO::PARAM_STR);
    $sth->bindParam(':description', $description, PDO::PARAM_STR);
    return $sth->execute();
}
예제 #8
0
function verifyUserIsAdmin($username)
{
    $dbh = new PDOConnection();
    $query = 'SELECT user_id FROM admins JOIN users ON users.id = user_id WHERE username = :username';
    $sth = $dbh->prepare($query);
    $sth->bindParam(':username', $username, PDO::PARAM_STR);
    if (!$sth->execute()) {
        throw new Exception($sth->errorInfo()[2]);
    }
    $result = $sth->fetchAll();
    $retval = !empty($result);
    return $retval;
}
예제 #9
0
function get_product_classes($classFilters = NULL)
{
    $dbh = new PDOConnection();
    $query = "SELECT * FROM product_classes ";
    $classArray = array();
    $sth = $dbh->prepare($query);
    $sth->execute();
    $result = $sth->fetchAll(PDO::FETCH_ASSOC);
    foreach ($result as $row) {
        $classArray[] = $row;
    }
    return $classArray;
}
예제 #10
0
function update_user($user)
{
    if (!(isset($user['email']) || isset($user['username']) || isset($user['password']))) {
        throw new Exception("Nothing changed!");
    }
    $dbh = new PDOConnection();
    $query = "SELECT id,username,email,password,token,last_updated FROM users WHERE id = :id";
    $sth = $dbh->prepare($query);
    $id = $user['user_id'];
    $sth->bindParam(':id', $id, PDO::PARAM_INT);
    if (!$sth->execute()) {
        throw new Exception($sth->errorInfo()[2]);
    }
    if (!($oldValues = $sth->fetch())) {
        throw new Exception("User id: '" . $id . "' not found!");
    }
    // if you change username you must provide password
    if (isset($user['username']) && !isset($user['password'])) {
        throw new Exception("Must provide password to change username.");
    }
    $email = isset($user['email']) ? $user['email'] : $oldValues['email'];
    $username = isset($user['username']) ? $user['username'] : $oldValues['username'];
    $password = isset($user['password']) ? hash_password($user['password'], $username) : $oldValues['password'];
    $token = $oldValues['token'];
    $query = "UPDATE users \n        SET username = :username, email = :email, password = :password \n        WHERE id = :id";
    $sth = $dbh->prepare($query);
    $sth->bindParam(':id', $id, PDO::PARAM_INT);
    $sth->bindParam(':username', $username);
    $sth->bindParam(':email', $email);
    $sth->bindParam(':password', $password);
    if (!$sth->execute()) {
        throw new Exception($sth->errorInfo()[2]);
    }
    if (isset($user['password'])) {
        $token = GenerateToken($username, $user['password']);
        StoreToken($username, $token);
    }
    return array('id' => $id, 'email' => $email, 'username' => $username, 'token' => $token);
}
예제 #11
0
function update_product_class($classArray)
{
    $dbh = new PDOConnection();
    $query = "SELECT id,code,description,last_updated FROM product_classes WHERE id = :id";
    $sth = $dbh->prepare($query);
    $id = $classArray['id'];
    $sth->bindParam(':id', $id, PDO::PARAM_INT);
    if (!$sth->execute()) {
        throw new Exception($sth->errorInfo()[2]);
    }
    if (!($oldValues = $sth->fetch())) {
        throw new Exception("Class id: '" . $id . "' not found!");
    }
    $query = "UPDATE product_classes SET code = :code, description = :description WHERE id = :id";
    $sth = $dbh->prepare($query);
    $code = isset($classArray['code']) ? $classArray['code'] : $oldValues['code'];
    $description = isset($classArray['description']) ? $classArray['description'] : $oldValues['description'];
    $sth->bindParam(':id', $id, PDO::PARAM_INT);
    $sth->bindParam(':code', $code);
    $sth->bindParam(':description', $description);
    $sth->execute();
    return true;
}
예제 #12
0
function add_unit($unitArray)
{
    $dbh = new PDOConnection();
    $code = $unitArray['code'];
    $description = $unitArray['description'];
    $query = "SELECT id,code FROM units WHERE code = :code";
    $sth = $dbh->prepare($query);
    $sth->bindParam(':code', $code, PDO::PARAM_STR);
    if (!$sth->execute()) {
        throw new Exception($sth->errorInfo()[2]);
    }
    if ($sth->rowCount() > 0) {
        throw new Exception("Unit code exists");
    }
    $query = "INSERT INTO units(code, description) VALUES(:code, :description)";
    $sth = $dbh->prepare($query);
    $sth->bindParam(':code', $code, PDO::PARAM_STR);
    $sth->bindParam(':description', $description, PDO::PARAM_STR);
    if (!$sth->execute()) {
        throw new Exception($sth->errorInfo()[2]);
    }
    return true;
}
예제 #13
0
function get_units($filters = NULL)
{
    $dbh = new PDOConnection();
    $query = "SELECT id, code, description, active, last_updated FROM units ";
    $query .= GetOptionalParams($filters);
    $units = array();
    $sth = $dbh->prepare($query);
    if (isset($filters['id'])) {
        $sth->bindParam(':id', $filters['id'], PDO::PARAM_INT);
    } elseif (isset($filters['code'])) {
        $sth->bindParam(':code', $filters['code']);
    }
    $sth->execute();
    $result = $sth->fetchAll(PDO::FETCH_ASSOC);
    foreach ($result as $row) {
        $units[] = $row;
    }
    return $units;
}
예제 #14
0
function get_customers($values = NULL)
{
    $dbh = new PDOConnection();
    $query = "SELECT id, code, name, active, last_updated FROM customers ";
    if (isset($values['id'])) {
        $optional[] = "id = :id ";
    }
    if (isset($values['code'])) {
        $optional[] = "code = :code ";
    }
    if (isset($values['active'])) {
        $optional[] = "active = :active ";
    }
    if (!empty($optional)) {
        $query .= ' WHERE ';
        $countOpt = count($optional);
        for ($i = 0; $i < $countOpt; ++$i) {
            $query .= ($i > 0 ? ' AND ' : ' ') . $optional[$i];
        }
    }
    $sth = $dbh->prepare($query);
    if (isset($values['id'])) {
        $sth->bindParam(':id', $values['id'], PDO::PARAM_INT);
    }
    if (isset($values['code'])) {
        $sth->bindParam(':code', $values['code'], PDO::PARAM_STR);
    }
    if (isset($values['active'])) {
        $sth->bindParam(':active', $values['active'], PDO::PARAM_INT);
    }
    if (!$sth->execute()) {
        throw new Exception($sth->errorInfo()[2]);
    }
    $customerArray = array();
    foreach ($sth->fetchAll(PDO::FETCH_ASSOC) as $row) {
        $customerArray[] = $row;
    }
    return array('customers' => $customerArray);
}
예제 #15
0
function get_cart($cartInfo)
{
    $dbh = new PDOConnection();
    $query = "SELECT u.id user_id, u.username, u.email, h.address_id, delivery_date, delivery_method, shipping_type, comments, shipping_comments, h.last_updated \n        FROM cart_headers h \n        LEFT JOIN users u ON u.id = h.user_id \n        WHERE user_id = :user_id ";
    $user_id = $cartInfo['user_id'];
    $sth = $dbh->prepare($query);
    $sth->bindParam(':user_id', $user_id);
    if (!$sth->execute()) {
        throw new Exception('ERROR in get_cart(): ' . $sth->errorInfo()[2]);
    }
    if ($sth->rowCount() <= 0) {
        throw new Exception('No cart found for user_id: ' . $user_id);
    }
    $cartArray = $sth->fetch(PDO::FETCH_ASSOC);
    $details = get_cart_details($dbh, $user_id);
    //calculate total price
    $cartArray['total_price'] = array_sum(array_map(function ($row) {
        return $row['line_price'];
    }, $details));
    //uncomment if you want details passed in the main get_cart function
    $cartArray['lines'] = $details;
    return $cartArray;
}
예제 #16
0
function get_warehouses($opts = NULL)
{
    $dbh = new PDOConnection();
    //not supported yet
    $customer_id = isset($opts['customer_id']) ? $opts['customer_id'] : '';
    //not supported yet
    $query = "SELECT id, code, name, address1, address2, city, state, zipcode, delivery_allowed, active, last_updated FROM warehouses ";
    if (isset($opts['id'])) {
        $query .= " WHERE id = :id";
    }
    $sth = $dbh->prepare($query);
    if (isset($opts['id'])) {
        $sth->bindParam(':id', $opts['id'], PDO::PARAM_INT);
    }
    if (!$sth->execute()) {
        throw new Exception($sth->errorInfo()[2]);
    }
    $warehouses = array();
    foreach ($sth->fetchAll(PDO::FETCH_ASSOC) as $row) {
        $warehouses[] = $row;
    }
    return $warehouses;
}
예제 #17
0
function get_products($info = NULL, &$error = NULL)
{
    $dbh = new PDOConnection();
    $query = "SELECT p.id product_id, p.code product_code, p.description product_desc, p.price, pc.id class_id, pc.code class_code, pc.description class_desc \n        FROM products p \n        LEFT JOIN product_classes pc ON p.class = pc.id ";
    $optionalParams = '';
    $code = '';
    if (isset($info['code'])) {
        $optionalParams .= 'p.code = :prod_code ';
        $code = $info['code'];
    }
    if ($optionalParams != '') {
        $query .= "WHERE " . $optionalParams;
    }
    $sth = $dbh->prepare($query);
    $paramArray = array(':prod_code' => $code);
    $sth->execute($paramArray);
    $productArray = array();
    $result = $sth->fetchAll(PDO::FETCH_ASSOC);
    foreach ($result as $row) {
        $productArray[] = $row;
    }
    return array('products' => $productArray);
}
예제 #18
0
function get_users($values = NULL)
{
    $dbh = new PDOConnection();
    $query = "SELECT id, username, email FROM users ";
    if (isset($values['id'])) {
        $optional .= "id = :id ";
    }
    if (isset($optional) && $optional !== '') {
        $query .= ' WHERE ' . $optional;
    }
    $sth = $dbh->prepare($query);
    if (isset($values['id'])) {
        $sth->bindParam(':id', $values['id'], PDO::PARAM_INT);
    }
    if (!$sth->execute()) {
        throw new Exception($sth->errorInfo()[2]);
    }
    $userArray = array();
    foreach ($sth->fetchAll(PDO::FETCH_ASSOC) as $row) {
        $userArray[] = $row;
    }
    return array('users' => $userArray);
}
예제 #19
0
function get_product_units($info = NULL)
{
    $dbh = new PDOConnection();
    $query = "SELECT \n                pu.id product_unit_id,\n                p.id product_id, \n                p.code product_code, \n                p.description product_description, \n                pu.price, \n                pc.id class_id, \n                pc.code class_code, \n                pc.description class_description, \n                u.id unit_id, \n                u.code unit_code, \n                u.description unit_description \n            FROM product_unit pu\n            LEFT JOIN units u ON pu.unit_id = u.id \n            LEFT JOIN products p ON pu.product_id = p.id \n            LEFT JOIN product_classes pc ON p.class = pc.id ";
    $optionalParams = array();
    if (isset($info['product_code'])) {
        $optionalParams[] = 'p.code = :product_code ';
        $product_code = $info['product_code'];
    }
    if (count($optionalParams) > 0) {
        $query .= "WHERE ";
        $query .= implode("AND ", $optionalParams);
    }
    $sth = $dbh->prepare($query);
    if (isset($product_code)) {
        $sth->bindParam(':product_code', $product_code);
    }
    $sth->execute();
    $productArray = array();
    foreach ($sth->fetchAll(PDO::FETCH_ASSOC) as $row) {
        $productArray[] = $row;
    }
    return array('product_units' => $productArray);
}
예제 #20
0
function get_order_detail($values)
{
    if (!isset($values['order_id'])) {
        throw new Exception("Must provide order_id");
    }
    $dbh = new PDOConnection();
    //get header information - this returns array of orders, so just grab the first one
    $result = get_orders(array('order_id' => $values['order_id'], 'details' => 1));
    $orderHeader = $result['orders'][0];
    $query = "SELECT \n            od.id line_key, \n            od.line_id,\n            od.price unit_price, \n            quantity, \n            p.id product_id, \n            p.code product_code, \n            p.description product_description, \n            unit_id, \n            u.code unit_code, \n            u.description unit_description,\n            (od.price * od.quantity) line_price\n        FROM order_details od \n        LEFT JOIN products p ON od.product_id = p.id \n        LEFT JOIN units u ON unit_id = u.id \n        WHERE order_id = :order_id ";
    $sth = $dbh->prepare($query);
    $sth->bindParam(':order_id', $values['order_id']);
    $detailArray = array();
    if (!$sth->execute()) {
        throw new Exception("ERROR: Could not retrieve order lines - " . $sth->errorInfo[2]);
    }
    foreach ($sth->fetchAll(PDO::FETCH_ASSOC) as $row) {
        $detailArray[] = $row;
    }
    $orderDetails = $orderHeader;
    $orderDetails['lines'] = $detailArray;
    return $orderDetails;
}
예제 #21
0
/**
 * Standardise table columns.
 *
 * @param PDOConnection $connection The PDO connection instance.
 *
 * @return void
 */
function upgrade_columns($connection)
{
    $prefix = $GLOBALS['ZConfig']['System']['prefix'];
    $commands = array();
    $commands[] = "ALTER TABLE {$prefix}_admin_category CHANGE pn_cid cid INT(11) NOT NULL AUTO_INCREMENT";
    $commands[] = "ALTER TABLE {$prefix}_admin_category CHANGE pn_name name VARCHAR(32) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_admin_category CHANGE pn_description description VARCHAR(254) NOT NULL";
    $commands[] = "RENAME TABLE {$prefix}_admin_category TO admin_category";
    $commands[] = "ALTER TABLE {$prefix}_admin_module CHANGE pn_amid amid INT(11) NOT NULL AUTO_INCREMENT";
    $commands[] = "ALTER TABLE {$prefix}_admin_module CHANGE pn_mid mid INT(11) DEFAULT '0' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_admin_module CHANGE pn_cid cid INT(11) DEFAULT '0' NOT NULL";
    $commands[] = "RENAME TABLE {$prefix}_admin_module TO admin_module";
    $commands[] = "ALTER TABLE {$prefix}_blocks CHANGE pn_bid bid INT(11) AUTO_INCREMENT";
    $commands[] = "ALTER TABLE {$prefix}_blocks CHANGE pn_bkey bkey VARCHAR(255) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_blocks CHANGE pn_title title VARCHAR(255) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_blocks CHANGE pn_content content LONGTEXT NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_blocks CHANGE pn_url url LONGTEXT NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_blocks CHANGE pn_mid mid INT(11) DEFAULT '0' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_blocks CHANGE pn_filter filter LONGTEXT NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_blocks CHANGE pn_active active TINYINT DEFAULT '1' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_blocks CHANGE pn_collapsable collapsable INT(11) DEFAULT '1' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_blocks CHANGE pn_defaultstate defaultstate INT(11) DEFAULT '1' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_blocks CHANGE pn_refresh refresh INT(11) DEFAULT '0' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_blocks CHANGE pn_last_update last_update DATETIME NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_blocks CHANGE pn_language language VARCHAR(30) NOT NULL";
    $commands[] = "RENAME TABLE {$prefix}_blocks TO blocks";
    $commands[] = "ALTER TABLE {$prefix}_userblocks CHANGE pn_uid uid INT(11) DEFAULT '0' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_userblocks CHANGE pn_bid bid INT(11) DEFAULT '0' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_userblocks CHANGE pn_active active TINYINT DEFAULT '1' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_userblocks CHANGE pn_last_update last_update DATETIME";
    $commands[] = "RENAME TABLE {$prefix}_userblocks TO userblocks";
    $commands[] = "ALTER TABLE {$prefix}_block_positions CHANGE pn_pid pid INT(11) AUTO_INCREMENT";
    $commands[] = "ALTER TABLE {$prefix}_block_positions CHANGE pn_name name VARCHAR(255) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_block_positions CHANGE pn_description description VARCHAR(255) NOT NULL";
    $commands[] = "RENAME TABLE {$prefix}_block_positions TO block_positions";
    $commands[] = "ALTER TABLE {$prefix}_block_placements CHANGE pn_pid pid INT(11) DEFAULT '0' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_block_placements CHANGE pn_bid bid INT(11) DEFAULT '0' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_block_placements CHANGE pn_order sortorder INT(11) DEFAULT '0' NOT NULL";
    $commands[] = "RENAME TABLE {$prefix}_block_placements TO block_placements";
    $commands[] = "ALTER TABLE {$prefix}_group_membership CHANGE pn_gid gid INT(11) DEFAULT '0' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_group_membership CHANGE pn_uid uid INT(11) DEFAULT '0' NOT NULL";
    $commands[] = "RENAME TABLE {$prefix}_group_membership TO group_membership";
    $commands[] = "ALTER TABLE {$prefix}_groups CHANGE pn_gid gid INT(11) AUTO_INCREMENT";
    $commands[] = "ALTER TABLE {$prefix}_groups CHANGE pn_name name VARCHAR(255) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_groups CHANGE pn_gtype gtype TINYINT DEFAULT '0' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_groups CHANGE pn_description description VARCHAR(200) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_groups CHANGE pn_prefix prefix VARCHAR(25) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_groups CHANGE pn_state state TINYINT DEFAULT '0' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_groups CHANGE pn_nbuser nbuser INT(11) DEFAULT '0' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_groups CHANGE pn_nbumax nbumax INT(11) DEFAULT '0' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_groups CHANGE pn_link link INT(11) DEFAULT '0' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_groups CHANGE pn_uidmaster uidmaster INT(11) DEFAULT '0' NOT NULL";
    $commands[] = "RENAME TABLE {$prefix}_groups TO groups";
    $commands[] = "ALTER TABLE {$prefix}_group_applications CHANGE pn_app_id app_id INT(11) NOT NULL AUTO_INCREMENT";
    $commands[] = "ALTER TABLE {$prefix}_group_applications CHANGE pn_uid uid INT(11) DEFAULT '0' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_group_applications CHANGE pn_gid gid INT(11) DEFAULT '0' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_group_applications CHANGE pn_application application LONGBLOB NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_group_applications CHANGE pn_status status TINYINT DEFAULT '0' NOT NULL";
    $commands[] = "RENAME TABLE {$prefix}_group_applications TO group_applications";
    $commands[] = "ALTER TABLE {$prefix}_hooks CHANGE pn_id id BIGINT AUTO_INCREMENT";
    $commands[] = "ALTER TABLE {$prefix}_hooks CHANGE pn_object object VARCHAR(64) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_hooks CHANGE pn_action action VARCHAR(64) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_hooks CHANGE pn_smodule smodule VARCHAR(64) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_hooks CHANGE pn_stype stype VARCHAR(64) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_hooks CHANGE pn_tarea tarea VARCHAR(64) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_hooks CHANGE pn_tmodule tmodule VARCHAR(64) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_hooks CHANGE pn_ttype ttype VARCHAR(64) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_hooks CHANGE pn_tfunc tfunc VARCHAR(64) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_hooks CHANGE pn_sequence sequence INT(11) DEFAULT '0' NOT NULL";
    $commands[] = "RENAME TABLE {$prefix}_hooks TO hooks";
    $commands[] = "ALTER TABLE {$prefix}_modules CHANGE pn_id id INT(11) AUTO_INCREMENT";
    $commands[] = "ALTER TABLE {$prefix}_modules CHANGE pn_name name VARCHAR(64) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_modules CHANGE pn_type type TINYINT DEFAULT '0' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_modules CHANGE pn_displayname displayname VARCHAR(64) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_modules CHANGE pn_url url VARCHAR(64) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_modules CHANGE pn_description description VARCHAR(255) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_modules CHANGE pn_regid regid INT(11) DEFAULT '0' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_modules CHANGE pn_directory directory VARCHAR(64) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_modules CHANGE pn_version version VARCHAR(10) DEFAULT '0' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_modules CHANGE pn_official official TINYINT DEFAULT '0' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_modules CHANGE pn_author author VARCHAR(255) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_modules CHANGE pn_contact contact VARCHAR(255) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_modules CHANGE pn_admin_capable admin_capable TINYINT DEFAULT '0' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_modules CHANGE pn_user_capable user_capable TINYINT DEFAULT '0' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_modules CHANGE pn_profile_capable profile_capable TINYINT DEFAULT '0' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_modules CHANGE pn_message_capable message_capable TINYINT DEFAULT '0' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_modules CHANGE pn_state state SMALLINT(6) DEFAULT '0' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_modules CHANGE pn_credits credits VARCHAR(255) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_modules CHANGE pn_changelog changelog VARCHAR(255) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_modules CHANGE pn_help help VARCHAR(255) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_modules CHANGE pn_license license VARCHAR(255) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_modules CHANGE pn_securityschema securityschema TEXT NOT NULL";
    $commands[] = "UPDATE {$prefix}_modules SET name = 'Extensions', displayname = 'Extensions', url = 'extensions', description = 'Manage your modules and plugins.', directory =  'Extensions', securityschema = 'a:1:{s:9:\"Extensions::\";s:2:\"::\";}' WHERE {$prefix}_modules.name = 'Modules'";
    $commands[] = "RENAME TABLE {$prefix}_modules TO modules";
    $commands[] = "ALTER TABLE {$prefix}_module_vars CHANGE pn_id id INT(11) AUTO_INCREMENT";
    $commands[] = "ALTER TABLE {$prefix}_module_vars CHANGE pn_modname modname VARCHAR(64) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_module_vars CHANGE pn_name name VARCHAR(64) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_module_vars CHANGE pn_value value LONGTEXT";
    $commands[] = "UPDATE {$prefix}_module_vars SET modname='Extensions' WHERE modname='Modules'";
    $commands[] = "RENAME TABLE {$prefix}_module_vars TO module_vars";
    $commands[] = "ALTER TABLE {$prefix}_module_deps CHANGE pn_id id INT(11) AUTO_INCREMENT";
    $commands[] = "ALTER TABLE {$prefix}_module_deps CHANGE pn_modid modid INT(11) DEFAULT '0' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_module_deps CHANGE pn_modname modname VARCHAR(64) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_module_deps CHANGE pn_minversion minversion VARCHAR(10) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_module_deps CHANGE pn_maxversion maxversion VARCHAR(10) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_module_deps CHANGE pn_status status TINYINT DEFAULT '0' NOT NULL";
    $commands[] = "RENAME TABLE {$prefix}_module_deps TO module_deps";
    $commands[] = "ALTER TABLE {$prefix}_group_perms CHANGE pn_pid pid INT(11) AUTO_INCREMENT";
    $commands[] = "ALTER TABLE {$prefix}_group_perms CHANGE pn_gid gid INT(11) DEFAULT '0' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_group_perms CHANGE pn_sequence sequence INT(11) DEFAULT '0' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_group_perms CHANGE pn_realm realm INT(11) DEFAULT '0' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_group_perms CHANGE pn_component component VARCHAR(255) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_group_perms CHANGE pn_instance instance VARCHAR(255) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_group_perms CHANGE pn_level level INT(11) DEFAULT '0' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_group_perms CHANGE pn_bond bond INT(11) DEFAULT '0' NOT NULL";
    $commands[] = "RENAME TABLE {$prefix}_group_perms TO group_perms";
    $commands[] = "ALTER TABLE {$prefix}_search_stat CHANGE pn_id id INT(11) AUTO_INCREMENT";
    $commands[] = "ALTER TABLE {$prefix}_search_stat CHANGE pn_search search VARCHAR(50) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_search_stat CHANGE pn_count scount INT(11) DEFAULT '0' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_search_stat CHANGE pn_date date DATE";
    $commands[] = "RENAME TABLE {$prefix}_search_stat TO search_stat";
    $commands[] = "ALTER TABLE {$prefix}_search_result CHANGE sres_id id INT(11) AUTO_INCREMENT";
    $commands[] = "ALTER TABLE {$prefix}_search_result CHANGE sres_title title VARCHAR(255) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_search_result CHANGE sres_text text LONGTEXT";
    $commands[] = "ALTER TABLE {$prefix}_search_result CHANGE sres_module module VARCHAR(100)";
    $commands[] = "ALTER TABLE {$prefix}_search_result CHANGE sres_extra extra VARCHAR(100)";
    $commands[] = "ALTER TABLE {$prefix}_search_result CHANGE sres_created created DATETIME";
    $commands[] = "ALTER TABLE {$prefix}_search_result CHANGE sres_found found DATETIME";
    $commands[] = "ALTER TABLE {$prefix}_search_result CHANGE sres_sesid sesid VARCHAR(50)";
    $commands[] = "RENAME TABLE {$prefix}_search_result TO search_result";
    $commands[] = "ALTER TABLE {$prefix}_themes CHANGE pn_id id INT(11) AUTO_INCREMENT";
    $commands[] = "ALTER TABLE {$prefix}_themes CHANGE pn_name name VARCHAR(64) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_themes CHANGE pn_type type TINYINT DEFAULT '0' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_themes CHANGE pn_displayname displayname VARCHAR(64) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_themes CHANGE pn_description description VARCHAR(255) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_themes CHANGE pn_regid regid INT(11) DEFAULT '0' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_themes CHANGE pn_directory directory VARCHAR(64) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_themes CHANGE pn_version version VARCHAR(10) DEFAULT '0' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_themes CHANGE pn_official official TINYINT DEFAULT '0' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_themes CHANGE pn_author author VARCHAR(255) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_themes CHANGE pn_contact contact VARCHAR(255) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_themes CHANGE pn_admin admin TINYINT DEFAULT '0' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_themes CHANGE pn_user user TINYINT DEFAULT '0' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_themes CHANGE pn_system system TINYINT DEFAULT '0' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_themes CHANGE pn_state state TINYINT DEFAULT '0' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_themes CHANGE pn_credits credits VARCHAR(255) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_themes CHANGE pn_changelog changelog VARCHAR(255) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_themes CHANGE pn_help help VARCHAR(255) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_themes CHANGE pn_license license VARCHAR(255) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_themes CHANGE pn_xhtml xhtml TINYINT DEFAULT '1' NOT NULL";
    $commands[] = "RENAME TABLE {$prefix}_themes TO themes";
    $commands[] = "ALTER TABLE {$prefix}_users CHANGE pn_uid uid INT(11) AUTO_INCREMENT";
    $commands[] = "ALTER TABLE {$prefix}_users CHANGE pn_uname uname VARCHAR(25) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_users CHANGE pn_email email VARCHAR(60) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_users CHANGE pn_user_regdate user_regdate DATETIME DEFAULT '1970-01-01 00:00:00' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_users CHANGE pn_user_viewemail user_viewemail SMALLINT DEFAULT '0'";
    $commands[] = "ALTER TABLE {$prefix}_users CHANGE pn_user_theme user_theme VARCHAR(64)";
    $commands[] = "ALTER TABLE {$prefix}_users CHANGE pn_pass pass VARCHAR(128) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_users CHANGE pn_storynum storynum INT DEFAULT '10' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_users CHANGE pn_ublockon ublockon TINYINT DEFAULT '0' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_users CHANGE pn_ublock ublock TEXT NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_users CHANGE pn_theme theme VARCHAR(255) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_users CHANGE pn_counter counter INT(11) DEFAULT '0' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_users CHANGE pn_activated activated TINYINT DEFAULT '0' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_users CHANGE pn_lastlogin lastlogin DATETIME DEFAULT '1970-01-01 00:00:00' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_users CHANGE pn_validfrom validfrom INT(11) DEFAULT '0' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_users CHANGE pn_validuntil validuntil INT(11) DEFAULT '0' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_users CHANGE pn_hash_method hash_method TINYINT(4) DEFAULT '8' NOT NULL";
    $commands[] = "RENAME TABLE {$prefix}_users TO users";
    $commands[] = "ALTER TABLE {$prefix}_users_temp CHANGE pn_tid tid INT(11) AUTO_INCREMENT";
    $commands[] = "ALTER TABLE {$prefix}_users_temp CHANGE pn_uname uname VARCHAR(25) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_users_temp CHANGE pn_email email VARCHAR(60) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_users_temp CHANGE pn_femail femail TINYINT(4) DEFAULT '0' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_users_temp CHANGE pn_pass pass VARCHAR(128) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_users_temp CHANGE pn_dynamics dynamics LONGTEXT NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_users_temp CHANGE pn_comment comment VARCHAR(254) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_users_temp CHANGE pn_type type TINYINT(4) DEFAULT '0' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_users_temp CHANGE pn_tag tag TINYINT(4) DEFAULT '0' NOT NULL";
    $commands[] = "RENAME TABLE {$prefix}_users_temp TO users_temp";
    $commands[] = "ALTER TABLE {$prefix}_session_info CHANGE pn_sessid sessid VARCHAR(40) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_session_info CHANGE pn_ipaddr ipaddr VARCHAR(32) NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_session_info CHANGE pn_lastused lastused DATETIME DEFAULT '1970-01-01 00:00:00'";
    $commands[] = "ALTER TABLE {$prefix}_session_info CHANGE pn_uid uid INT(11) DEFAULT '0'";
    $commands[] = "ALTER TABLE {$prefix}_session_info CHANGE pn_remember remember TINYINT DEFAULT '0' NOT NULL";
    $commands[] = "ALTER TABLE {$prefix}_session_info CHANGE pn_vars vars LONGTEXT NOT NULL";
    $commands[] = "RENAME TABLE {$prefix}_session_info TO session_info";
    $commands[] = "RENAME TABLE {$prefix}_categories_category TO categories_category";
    $commands[] = "ALTER TABLE `categories_category` CHANGE `cat_id` `id` INT(11) NOT NULL AUTO_INCREMENT, CHANGE `cat_parent_id` `parent_id` INT(11) NOT NULL DEFAULT '1', CHANGE `cat_is_locked` `is_locked` TINYINT(4) NOT NULL DEFAULT '0', CHANGE `cat_is_leaf` `is_leaf` TINYINT(4) NOT NULL DEFAULT '0', CHANGE `cat_name` `name` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '', CHANGE `cat_value` `value` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '', CHANGE `cat_sort_value` `sort_value` INT(11) NOT NULL DEFAULT '0', CHANGE `cat_display_name` `display_name` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, CHANGE `cat_display_desc` `display_desc` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, CHANGE `cat_path` `path` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, CHANGE `cat_ipath` `ipath` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '', CHANGE `cat_status` `status` VARCHAR(1) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'A', CHANGE `cat_obj_status` `obj_status` VARCHAR(1) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'A', CHANGE `cat_cr_date` `cr_date` DATETIME NOT NULL DEFAULT '1970-01-01 00:00:00', CHANGE `cat_cr_uid` `cr_uid` INT(11) NOT NULL DEFAULT '0', CHANGE `cat_lu_date` `lu_date` DATETIME NOT NULL DEFAULT '1970-01-01 00:00:00', CHANGE `cat_lu_uid` `lu_uid` INT(11) NOT NULL DEFAULT '0'";
    $commands[] = "RENAME TABLE {$prefix}_categories_mapmeta TO categories_mapmeta";
    $commands[] = "ALTER TABLE `categories_mapmeta` CHANGE  `cmm_id`  `id` INT( 11 ) NOT NULL AUTO_INCREMENT ,\nCHANGE  `cmm_meta_id`  `meta_id` INT( 11 ) NOT NULL DEFAULT  '0',\nCHANGE  `cmm_category_id`  `category_id` INT( 11 ) NOT NULL DEFAULT  '0',\nCHANGE  `cmm_obj_status`  `obj_status` VARCHAR( 1 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT  'A',\nCHANGE  `cmm_cr_date`  `cr_date` DATETIME NOT NULL DEFAULT  '1970-01-01 00:00:00',\nCHANGE  `cmm_cr_uid`  `cr_uid` INT( 11 ) NOT NULL DEFAULT  '0',\nCHANGE  `cmm_lu_date`  `lu_date` DATETIME NOT NULL DEFAULT  '1970-01-01 00:00:00',\nCHANGE  `cmm_lu_uid`  `lu_uid` INT( 11 ) NOT NULL DEFAULT  '0'";
    $commands[] = "RENAME TABLE {$prefix}_categories_mapobj TO categories_mapobj";
    $commands[] = "ALTER TABLE `categories_mapobj` CHANGE `cmo_id` `id` INT(11) NOT NULL AUTO_INCREMENT, CHANGE `cmo_modname` `modname` VARCHAR(60) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '', CHANGE `cmo_table` `tablename` VARCHAR(60) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, CHANGE `cmo_obj_id` `obj_id` INT(11) NOT NULL DEFAULT '0', CHANGE `cmo_obj_idcolumn` `obj_idcolumn` VARCHAR(60) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'id', CHANGE `cmo_reg_id` `reg_id` INT(11) NOT NULL DEFAULT '0', CHANGE `cmo_category_id` `category_id` INT(11) NOT NULL DEFAULT '0', CHANGE `cmo_obj_status` `obj_status` VARCHAR(1) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'A', CHANGE `cmo_cr_date` `cr_date` DATETIME NOT NULL DEFAULT '1970-01-01 00:00:00', CHANGE `cmo_cr_uid` `cr_uid` INT(11) NOT NULL DEFAULT '0', CHANGE `cmo_lu_date` `lu_date` DATETIME NOT NULL DEFAULT '1970-01-01 00:00:00', CHANGE `cmo_lu_uid` `lu_uid` INT(11) NOT NULL DEFAULT '0'";
    $commands[] = "RENAME TABLE {$prefix}_categories_registry TO categories_registry";
    $commands[] = "ALTER TABLE `categories_registry` CHANGE `crg_id` `id` INT(11) NOT NULL AUTO_INCREMENT, CHANGE `crg_modname` `modname` VARCHAR(60) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '', CHANGE `crg_table` `tablename` VARCHAR(60) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '', CHANGE `crg_property` `property` VARCHAR(60) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '', CHANGE `crg_category_id` `category_id` INT(11) NOT NULL DEFAULT '0', CHANGE `crg_obj_status` `obj_status` VARCHAR(1) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'A', CHANGE `crg_cr_date` `cr_date` DATETIME NOT NULL DEFAULT '1970-01-01 00:00:00', CHANGE `crg_cr_uid` `cr_uid` INT(11) NOT NULL DEFAULT '0', CHANGE `crg_lu_date` `lu_date` DATETIME NOT NULL DEFAULT '1970-01-01 00:00:00', CHANGE `crg_lu_uid` `lu_uid` INT(11) NOT NULL DEFAULT '0'";
    $commands[] = "RENAME TABLE {$prefix}_objectdata_attributes TO objectdata_attributes";
    $commands[] = "ALTER TABLE `objectdata_attributes` CHANGE `oba_id` `id` INT(11) NOT NULL AUTO_INCREMENT, CHANGE `oba_attribute_name` `attribute_name` VARCHAR(80) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '', CHANGE `oba_object_id` `object_id` INT(11) NOT NULL DEFAULT '0', CHANGE `oba_object_type` `object_type` VARCHAR(80) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '', CHANGE `oba_value` `value` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, CHANGE `oba_obj_status` `obj_status` VARCHAR(1) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'A', CHANGE `oba_cr_date` `cr_date` DATETIME NOT NULL DEFAULT '1970-01-01 00:00:00', CHANGE `oba_cr_uid` `cr_uid` INT(11) NOT NULL DEFAULT '0', CHANGE `oba_lu_date` `lu_date` DATETIME NOT NULL DEFAULT '1970-01-01 00:00:00', CHANGE `oba_lu_uid` `lu_uid` INT(11) NOT NULL DEFAULT '0'";
    $commands[] = "RENAME TABLE {$prefix}_objectdata_log TO objectdata_log";
    $commands[] = "ALTER TABLE `objectdata_log` CHANGE `obl_id` `id` INT(11) NOT NULL AUTO_INCREMENT, CHANGE `obl_object_type` `object_type` VARCHAR(80) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '', CHANGE `obl_object_id` `object_id` INT(11) NOT NULL DEFAULT '0', CHANGE `obl_op` `op` VARCHAR(16) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '', CHANGE `obl_diff` `diff` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, CHANGE `obl_obj_status` `obj_status` VARCHAR(1) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'A', CHANGE `obl_cr_date` `cr_date` DATETIME NOT NULL DEFAULT '1970-01-01 00:00:00', CHANGE `obl_cr_uid` `cr_uid` INT(11) NOT NULL DEFAULT '0', CHANGE `obl_lu_date` `lu_date` DATETIME NOT NULL DEFAULT '1970-01-01 00:00:00', CHANGE `obl_lu_uid` `lu_uid` INT(11) NOT NULL DEFAULT '0'";
    $commands[] = "RENAME TABLE {$prefix}_objectdata_meta TO objectdata_meta";
    $commands[] = "ALTER TABLE `objectdata_meta` CHANGE `obm_id` `id` INT(11) NOT NULL AUTO_INCREMENT, CHANGE `obm_module` `module` VARCHAR(40) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '', CHANGE `obm_table` `tablename` VARCHAR(40) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '', CHANGE `obm_idcolumn` `idcolumn` VARCHAR(40) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '', CHANGE `obm_obj_id` `obj_id` INT(11) NOT NULL DEFAULT '0', CHANGE `obm_permissions` `permissions` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, CHANGE `obm_dc_title` `dc_title` VARCHAR(80) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, CHANGE `obm_dc_author` `dc_author` VARCHAR(80) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, CHANGE `obm_dc_subject` `dc_subject` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, CHANGE `obm_dc_keywords` `dc_keywords` VARCHAR(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, CHANGE `obm_dc_description` `dc_description` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, CHANGE `obm_dc_publisher` `dc_publisher` VARCHAR(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, CHANGE `obm_dc_contributor` `dc_contributor` VARCHAR(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, CHANGE `obm_dc_startdate` `dc_startdate` DATETIME NULL DEFAULT '1970-01-01 00:00:00', CHANGE `obm_dc_enddate` `dc_enddate` DATETIME NULL DEFAULT '1970-01-01 00:00:00', CHANGE `obm_dc_type` `dc_type` VARCHAR(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, CHANGE `obm_dc_format` `dc_format` VARCHAR(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, CHANGE `obm_dc_uri` `dc_uri` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, CHANGE `obm_dc_source` `dc_source` VARCHAR(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, CHANGE `obm_dc_language` `dc_language` VARCHAR(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, CHANGE `obm_dc_relation` `dc_relation` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, CHANGE `obm_dc_coverage` `dc_coverage` VARCHAR(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, CHANGE `obm_dc_entity` `dc_entity` VARCHAR(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, CHANGE `obm_dc_comment` `dc_comment` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, CHANGE `obm_dc_extra` `dc_extra` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, CHANGE `obm_obj_status` `obj_status` VARCHAR(1) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'A', CHANGE `obm_cr_date` `cr_date` DATETIME NOT NULL DEFAULT '1970-01-01 00:00:00', CHANGE `obm_cr_uid` `cr_uid` INT(11) NOT NULL DEFAULT '0', CHANGE `obm_lu_date` `lu_date` DATETIME NOT NULL DEFAULT '1970-01-01 00:00:00', CHANGE `obm_lu_uid` `lu_uid` INT(11) NOT NULL DEFAULT '0'";
    $commands[] = "DROP TABLE {$prefix}_sc_anticracker";
    $commands[] = "DROP TABLE {$prefix}_sc_log_event";
    $commands[] = "UPDATE module_vars SET modname = 'ZConfig' WHERE modname = '/PNConfig'";
    $silentCommands = array();
    $silentCommands[] = "ALTER TABLE {$prefix}_message CHANGE pn_mid mid INT(11) NOT NULL AUTO_INCREMENT ,\nCHANGE pn_title title VARCHAR(100) NOT NULL DEFAULT  '',\nCHANGE pn_content content LONGTEXT NOT NULL ,\nCHANGE pn_date date INT(11) NOT NULL DEFAULT  '0',\nCHANGE pn_expire expire INT(11) NOT NULL DEFAULT  '0',\nCHANGE pn_active active INT(11) NOT NULL DEFAULT  '1',\nCHANGE pn_view view INT(11) NOT NULL DEFAULT  '1',\nCHANGE pn_language language VARCHAR(30) NOT NULL DEFAULT  ''";
    $silentCommands[] = "ALTER TABLE {$prefix}_pagelock CHANGE plock_id id INT(11) NOT NULL AUTO_INCREMENT";
    $silentCommands[] = "ALTER TABLE {$prefix}_pagelock CHANGE plock_name name VARCHAR(100) NOT NULL";
    $silentCommands[] = "ALTER TABLE {$prefix}_pagelock CHANGE plock_cdate cdate DATETIME NOT NULL";
    $silentCommands[] = "ALTER TABLE {$prefix}_pagelock CHANGE plock_edate edate DATETIME NOT NULL";
    $silentCommands[] = "ALTER TABLE {$prefix}_pagelock CHANGE plock_session session VARCHAR(50) NOT NULL";
    $silentCommands[] = "ALTER TABLE {$prefix}_pagelock CHANGE plock_title title VARCHAR(100) NOT NULL";
    $silentCommands[] = "ALTER TABLE {$prefix}_pagelock CHANGE plock_ipno ipno VARCHAR(30) NOT NULL";
    $silentCommands[] = "RENAME TABLE {$prefix}_pagelock TO pagelock";
    // LONGBLOB is not supported by Doctrine 2
    $silentCommands[] = "ALTER TABLE {$prefix}_workflows CHANGE debug debug LONGTEXT NULL DEFAULT NULL";
    $silentCommands[] = "RENAME TABLE {$prefix}_workflows TO workflows";
    $silentCommands[] = "ALTER TABLE group_applications CHANGE application application LONGTEXT NOT NULL";
    // Handle case of andreas08 themes on linux environments.
    $silentCommands[] = "UPDATE themes SET name = 'Andreas08', directory = 'Andreas08' WHERE name = 'andreas08'";
    $silentCommands[] = "UPDATE module_vars SET value = 's:9:\"Andreas08\";' WHERE modname = 'ZConfig' AND value ='s:9:\"andreas08\";'";
    foreach ($commands as $sql) {
        $stmt = $connection->prepare($sql);
        $stmt->execute();
    }
    foreach ($silentCommands as $sql) {
        $stmt = $connection->prepare($sql);
        try {
            $stmt->execute();
        } catch (Exception $e) {
            // Silent - trap and toss exceptions.
        }
    }
}