aktt = $wpdb->prefix.'ak_twitter';
function aktt_upgrade_30() {
global $wpdb;
$body = $head = $foot = '';
$errors = array();
// check for username in wp_options data
$username = get_option('aktt_twitter_username');
$username = 'foo';
if (empty($username)) {
$errors[] = '
'.__('Sorry, unable to find the legacy Tools for Twitter username. Check that the aktt_twitter_username is set in your Options table.', 'twitter-tools').'
';
}
// add upgraded col if needed
$cols = $wpdb->get_results("
DESCRIBE $wpdb->aktt;
");
$upgrade_col = false;
foreach ($cols as $col) {
if ($col->Field == 'upgrade_30') {
$upgrade_col = true;
break;
}
}
if (!$upgrade_col) {
$result = $wpdb->query("
ALTER TABLE $wpdb->aktt
ADD `upgrade_30` tinyint(1) default 0
AFTER modified
");
if (!$result) {
$errors[] = ''.__('Sorry, unable to alter the database table as needed for the upgrade. Please check your database user permissions.', 'twitter-tools').'
';
}
}
// make sure we have some tweets to upgrade
$count = $wpdb->get_var("
SELECT count(id)
FROM $wpdb->aktt
WHERE upgrade_30 = 0
");
if (!$count) {
$body = ''.__('Sorry, it doesn\'t look like any tweets need upgrading.', 'twitter-tools').'
';
}
// prep output
if (count($errors)) {
$body = implode("\n", $errors);
}
else {
ob_start();
?>
WARNING! Before you upgrade, please back up your data. Y\'know, just in case.', 'twitter-tools'); ?>
Tools for Twitter settings.', 'twitter-tools'), esc_url(admin_url('options-general.php?page=twitter-tools'))); ?>
get_results("
SELECT *
FROM $wpdb->aktt
WHERE upgrade_30 = 0
LIMIT $count
");
// upgrade
if (count($tweets)) {
$upgraded = array();
$username = get_option('aktt_twitter_username'); // already passed sanity check to make sure this exists
foreach ($tweets as $tweet) {
if (trim($tweet->tw_text) == '') {
continue;
}
$t = new AKTT_Tweet($tweet->tw_id);
$t->data = new stdClass;
$t->data->id = $t->data->id_str = $tweet->tw_id;
$t->data->text = $tweet->tw_text;
$t->data->created_at = date('D M d H:i:s +0000 Y', strtotime($tweet->tw_created_at.' +0000'));
$t->data->in_reply_to_screen_name = $tweet->tw_reply_username;
$t->data->in_reply_to_status_id = $t->data->in_reply_to_status_id_str = $tweet->tw_reply_tweet;
$t->data->user = new stdClass;
$t->data->user->screen_name = $username;
$t->raw_data = json_encode($t->data);
// skip if duplicate
if ($t->exists_by_guid()) {
// already there, so mark as upgraded
$upgraded[] = intval($tweet->id);
continue;
}
if ($t->add()) {
// add meta - upgraded tweet
update_post_meta($t->post_id, '_aktt_upgraded_30', 1);
update_post_meta($t->post_id, '_aktt_30_backfill_needed', 1);
$upgraded[] = intval($tweet->id);
}
}
if (count($upgraded)) {
$wpdb->query("
UPDATE $wpdb->aktt
SET upgrade_30 = 1
WHERE id IN (".implode(',', $upgraded).")
");
}
}
// return stats
$to_upgrade = $wpdb->get_var("
SELECT count(id)
FROM $wpdb->aktt
WHERE upgrade_30 = 0
");
return $to_upgrade;
}
function aktt_upgrade_30_shell($title = '', $body = '', $head = '', $foot = '') {
ob_start();
?>
>