/** * Deletes the rows from the user_events table which are associated to the current object. * * @return number */ public function delete_events_from_user_event_table() { global $wpdb; $user_event_table = Ai1ec_Facebook_Factory::get_user_events_table(); $query = $wpdb->prepare("DELETE FROM {$user_event_table} WHERE user_id = %s", $this->_id); $num_rows_deleted = $wpdb->query($query); return $num_rows_deleted; }
/** * Check if the current id is present in the user_events table. This is useful to know if the event can be deleted. * * @return boolean TRUE if the event is present, FALSE if it's not. */ public function check_if_someone_refers_the_event_in_the_user_events_table() { global $wpdb; $user_event_table = Ai1ec_Facebook_Factory::get_user_events_table(); // Check if at least on row exist $query = $wpdb->prepare("SELECT 1 as how_many FROM {$user_event_table} where eid = %s LIMIT 1", $this->id); $how_many = $wpdb->get_var($query); return (int) $how_many === 1; }
/** * (non-PHPdoc) * @see Ai1ec_Connector_Plugin::run_uninstall_procedures() */ public function run_uninstall_procedures() { // delete our scheduled crons $this->disable_cron_functions(); // Clean up opions delete_option(self::FB_OPTION_DB_VERSION); delete_option(self::FB_OPTION_CRON_VERSION); delete_option(self::FB_OPTION_CRON_NOTICE); // Delete tables global $wpdb; $plugin_table = Ai1ec_Facebook_Factory::get_plugin_table(); $user_events_table = Ai1ec_Facebook_Factory::get_user_events_table(); $wpdb->query("DROP TABLE IF EXISTS {$plugin_table}"); $wpdb->query("DROP TABLE IF EXISTS {$user_events_table}"); }
/** * Does nothing if the event is already present in the table, otherwis it insert it. * * @param bigint $user_id the id of the Facebook user * * @param bigint $eid the id of the Facebook event * * @param int $timestamp The starting time of the event * * @return boolean TRUE if no errors happened, FALSE otherwise. */ private function handle_saving_in_user_events_table($user_id, $eid, $timestamp) { global $wpdb; $table_name = Ai1ec_Facebook_Factory::get_user_events_table(); // Check if we already have the event in the DB $query = $wpdb->prepare("SELECT 'exist' FROM {$table_name} where user_id = %s AND eid = %s", $user_id, $eid); $exist = $wpdb->get_var($query); // If the query returned something just return true if ($exist !== NULL) { return TRUE; } $result = $wpdb->query($wpdb->prepare("INSERT INTO {$table_name} VALUES ( %s, %s, FROM_UNIXTIME( %d ) )", $user_id, $eid, $timestamp)); if ($result === FALSE) { return FALSE; } else { return TRUE; } }
/** * Does nothing if the event is already present in the table, otherwis it insert it. * * @param bigint $user_id the id of the Facebook user * * @param bigint $eid the id of the Facebook event * * @param int $timestamp The starting time of the event * * @return boolean TRUE if no errors' happened, FALSE otherwise. */ private function handle_saving_in_user_events_table($user_id, $eid, $timestamp) { global $wpdb; $table_name = Ai1ec_Facebook_Factory::get_user_events_table(); // Check if we already have the event in the DB $query = $wpdb->prepare('SELECT \'exist\' FROM ' . $table_name . ' WHERE user_id = %s AND eid = %s', $user_id, $eid); $exist = $wpdb->get_var($query); // If the query returned something just return true if (NULL !== $exist) { return true; } $result = $wpdb->query($wpdb->prepare('INSERT INTO ' . $table_name . ' ( `user_id`, `eid`, `start` )' . ' VALUES ( %s, %s, %d )', $user_id, $eid, $timestamp)); if (false === $result) { return false; } return true; }