Skip to content

Instantly share code, notes, and snippets.

@svenseeberg
Created January 14, 2020 10:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save svenseeberg/76a8b9cb8b7efc7bd65834e27ffda4af to your computer and use it in GitHub Desktop.
Save svenseeberg/76a8b9cb8b7efc7bd65834e27ffda4af to your computer and use it in GitHub Desktop.
Fix broken Events Manager database
<?php
$debug = true; //flip this switch if you're sure what you're doing
$configuration = parse_ini_file("config.ini", true);
// ** MySQL settings - You can get this info from your web host ** //
$db_configuration = $configuration['database'];
/** The name of the database for WordPress */
define('DB_NAME', $db_configuration['name']);
/** MySQL database username */
define('DB_USER', $db_configuration['user']);
/** MySQL database password */
define('DB_PASSWORD', $db_configuration['password']);
/** MySQL hostname */
define('DB_HOST', $db_configuration['host']);
/** Database Charset to use in creating database tables. */
define('DB_CHARSET', $db_configuration['charset']);
/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', $db_configuration['collate']);
$table_prefix = 'wp_';
$db = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
/* Get all blog IDs */
$query = "SELECT blog_id FROM " . $table_prefix . "blogs";
$result = $db->query( $query );
while( $row = $result->fetch_object() ) {
$query_table_version = "SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '" . $table_prefix . $row->blog_id . "_em_events' AND COLUMN_NAME = 'event_parent'";
$result_table_version = $db->query($query_table_version);
if($result_table_version->num_rows == 0) {
$update = "ALTER TABLE " . $table_prefix . $row->blog_id . "_em_events
ADD COLUMN event_parent bigint(20) unsigned NULL,
ADD COLUMN event_language varchar(14) NULL,
ADD COLUMN event_translation tinyint(1) unsigned NOT NULL DEFAULT 0,
MODIFY recurrence tinyint(1) unsigned NULL DEFAULT 0,
MODIFY event_private tinyint(1) unsigned NOT NULL DEFAULT 0,
MODIFY event_rsvp tinyint(1) unsigned NOT NULL DEFAULT 0,
MODIFY event_all_day tinyint(1) unsigned,
MODIFY event_status tinyint(1) unsigned";
if($debug)
var_dump( $update );
else {
var_dump( $update );
$res_update = $db->query( $update );
var_dump($db->error);
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment