<?php

namespace IGD;

defined( 'ABSPATH' ) || exit();

class Update_1_5_6 {
	private static $instance;

	private function __construct() {
		$this->maybe_alter_columns();
	}


	public function maybe_alter_columns() {
		global $wpdb;

		$table_name = $wpdb->prefix . 'integrate_google_drive_selections';

		//if table exists, add a new column tinyint(1) 'status' if it doesn't exist
		if ( $wpdb->get_var( "SHOW TABLES LIKE '$table_name'" ) === $table_name ) {
			$column = $wpdb->get_results( "SHOW COLUMNS FROM $table_name LIKE 'status'" );
			if ( empty( $column ) ) {
				$wpdb->query( "ALTER TABLE $table_name ADD COLUMN status TINYINT(1) NOT NULL DEFAULT 0 AFTER email" );
			}
		}

	}

	/**
	 * Gets the singleton instance of the class.
	 *
	 * @return Update_1_5_6
	 */
	public static function instance() {
		if ( self::$instance === null ) {
			self::$instance = new self();
		}

		return self::$instance;
	}
}

Update_1_5_6::instance();
