Skip to content

Instantly share code, notes, and snippets.

@little-apps
Created January 12, 2016 19:24
Show Gist options
  • Save little-apps/162e1198e3a01b5ddb22 to your computer and use it in GitHub Desktop.
Save little-apps/162e1198e3a01b5ddb22 to your computer and use it in GitHub Desktop.
This is to correct the error with the table data types in Little Software Stats v0.2.1.
<?php
/*
* This is to correct the error with the table data types in Little Software Stats v0.2.1.
*
* To use, upload this file to the base directory of Little Software Stats and then execute it.
*
* !!! REMOVE THIS FILE IMMEDIATELY AFTER USE !!!
**/
extension_loaded( 'mysqli' ) or die( 'MySQLi extension must be loaded.' );
require_once( 'inc/class.config.php' );
$config = Config::getInstance();
$db = @mysqli_connect( $config->mysql->host, $config->mysql->user, $config->mysql->pass );
if ( !$db )
die( 'Unable to connect to database. Please check inc/config.php file.' );
$db->select_db( $config->mysql->db );
$sql = <<<SQL
ALTER TABLE `{:db_prefix}sessions` ADD COLUMN `StartApp2` TIMESTAMP NULL DEFAULT NULL AFTER `StartApp`;
UPDATE `{:db_prefix}sessions` SET `StartApp2`=FROM_UNIXTIME(`StartApp`);
ALTER TABLE `{:db_prefix}sessions` DROP `StartApp`;
ALTER TABLE `{:db_prefix}sessions` CHANGE `StartApp2` `StartApp` TIMESTAMP NULL DEFAULT NULL;
ALTER TABLE `{:db_prefix}sessions` ADD COLUMN `StopApp2` TIMESTAMP NULL DEFAULT NULL AFTER `StopApp`;
UPDATE `{:db_prefix}sessions` SET `StopApp2`=FROM_UNIXTIME(`StopApp`);
ALTER TABLE `{:db_prefix}sessions` DROP `StopApp`;
ALTER TABLE `{:db_prefix}sessions` CHANGE `StopApp2` `StopApp` TIMESTAMP NULL DEFAULT NULL;
ALTER TABLE `{:db_prefix}uniqueusers` ADD COLUMN `Created2` TIMESTAMP NULL DEFAULT NULL AFTER `Created`;
UPDATE `{:db_prefix}uniqueusers` SET `Created2`=FROM_UNIXTIME(`Created`);
ALTER TABLE `{:db_prefix}uniqueusers` DROP `Created`;
ALTER TABLE `{:db_prefix}uniqueusers` CHANGE `Created2` `Created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;
ALTER TABLE `{:db_prefix}uniqueusers` ADD COLUMN `LastRecieved2` TIMESTAMP NULL DEFAULT NULL AFTER `LastRecieved`;
UPDATE `{:db_prefix}uniqueusers` SET `LastRecieved2`=FROM_UNIXTIME(`LastRecieved`);
ALTER TABLE `{:db_prefix}uniqueusers` DROP `LastRecieved`;
ALTER TABLE `{:db_prefix}uniqueusers` CHANGE `LastRecieved2` `LastRecieved` TIMESTAMP NOT NULL;
SQL;
$sql = str_replace( '{:db_prefix}', $config->mysql->prefix, $sql );
if ( $db->multi_query( $sql ) ) {
echo 'Sucessfully updated tables. Please delete this file.' . PHP_EOL;
} else {
echo sprintf( 'The following error occurred (#%d): %s', $db->errno, $db->error ) . PHP_EOL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment