imports working

This commit is contained in:
John Bintz 2009-10-25 14:11:48 -04:00
parent 89339c7d3b
commit b16ce4daae
3 changed files with 60 additions and 26 deletions

View File

@ -38,7 +38,7 @@ class WhatDidTheySayAdmin {
var $is_ajax = false; var $is_ajax = false;
var $_import_chunk_size = 50; var $_import_chunk_size = 20;
/** /**
* Initialize the admin interface. * Initialize the admin interface.
@ -321,6 +321,17 @@ class WhatDidTheySayAdmin {
array(&$this, 'manage_admin') array(&$this, 'manage_admin')
); );
if (current_user_can('approve_transcriptions')) {
add_submenu_page(
'tools.php',
__('Import Transcripts', 'what-did-they-say'),
__('Import Transcripts', 'what-did-they-say'),
'approve_transcriptions',
'import-transcripts',
array(&$this, 'manage_import_transcripts')
);
}
if ($plugin_page == "manage-wdts") { if ($plugin_page == "manage-wdts") {
$this->read_language_file(); $this->read_language_file();
wp_enqueue_style('wdts-admin', plugin_dir_url(dirname(__FILE__)) . 'css/wdts-admin.css'); wp_enqueue_style('wdts-admin', plugin_dir_url(dirname(__FILE__)) . 'css/wdts-admin.css');
@ -551,26 +562,32 @@ class WhatDidTheySayAdmin {
return $ok; return $ok;
} }
function _get_transcript_posts() {
global $wpdb;
return $wpdb->get_col("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = 'transcript'");
}
function import_transcripts($language_code) { function import_transcripts($language_code) {
$modified = false;
$posts = get_posts(array('posts_per_page' => $this->_import_chunk_size, 'meta_key' => 'transcript'));
if (!empty($posts)) {
$modified = 0; $modified = 0;
foreach ($posts as $post) { $post_ids = $this->_get_transcript_posts();
if ($transcript = get_post_meta($post->ID, 'transcript', true)) { if (!empty($post_ids)) {
$approved_transcript_manager = new WDTSApprovedTranscript($post->ID); $modified = 0;
foreach ($post_ids as $post_id) {
if ($transcript = get_post_meta($post_id, 'transcript', true)) {
$approved_transcript_manager = new WDTSApprovedTranscript($post_id);
$approved_transcript_manager->save_transcript(array( $approved_transcript_manager->save_transcript(array(
'language' => $language_code, 'language' => $language_code,
'transcript' => $transcript 'transcript' => $transcript
)); ));
}
delete_post_meta($post->ID, 'transcript'); delete_post_meta($post_id, 'transcript');
$modified++; $modified++;
if ($modified >= $this->_import_chunk_size) { break; }
} }
} }
if ($modified == 0) { $modified = false; }
}
return $modified; return $modified;
} }
@ -649,6 +666,16 @@ class WhatDidTheySayAdmin {
} }
} }
function handle_update_import_legacy($info) {
$this->is_ajax = true;
$result = $this->import_transcripts($info['language']);
if ($result === false) { $result = 'false'; }
header("X-JSON: '${result}'");
exit(0);
}
function handle_update_update_queued_transcript($info) { function handle_update_update_queued_transcript($info) {
$this->is_ajax = true; $this->is_ajax = true;
@ -1052,6 +1079,17 @@ class WhatDidTheySayAdmin {
$nonce = wp_create_nonce('what-did-they-say'); $nonce = wp_create_nonce('what-did-they-say');
include('partials/meta-box.inc'); include('partials/meta-box.inc');
} }
function manage_import_transcripts() {
global $wpdb;
$options = get_option('what-did-they-say-options');
$legacy_transcript_count = (int)$wpdb->get_var($wpdb->prepare("SELECT count($wpdb->postmeta.meta_key) FROM $wpdb->postmeta WHERE $wpdb->postmeta.meta_key = 'transcript'"));
$nonce = wp_create_nonce('what-did-they-say');
include('partials/import-transcripts.inc');
}
} }
?> ?>

View File

@ -85,7 +85,7 @@ class WhatDidTheySayAdminTest extends PHPUnit_Framework_TestCase {
* Integration. * Integration.
*/ */
function testPerformImport() { function testPerformImport() {
$admin = new WhatDidTheySayAdmin(); $admin = $this->getMock('WhatDidTheySayAdmin', array('_get_transcript_posts'));
$admin->_import_chunk_size = 1; $admin->_import_chunk_size = 1;
wp_insert_user(array('ID' => 1)); wp_insert_user(array('ID' => 1));
@ -98,13 +98,7 @@ class WhatDidTheySayAdminTest extends PHPUnit_Framework_TestCase {
update_post_meta($i, "transcript", "this is my transcript"); update_post_meta($i, "transcript", "this is my transcript");
} }
_set_up_get_posts_response(array( $admin->expects($this->once())->method('_get_transcript_posts')->will($this->returnValue(array(1,2)));
'posts_per_page' => 1,
'meta_key' => 'transcript'
), array(
get_post(1)
));
$this->assertEquals(1, $admin->import_transcripts('en')); $this->assertEquals(1, $admin->import_transcripts('en'));
$this->assertEquals('', get_post_meta(1, "transcript", true)); $this->assertEquals('', get_post_meta(1, "transcript", true));
@ -121,12 +115,12 @@ class WhatDidTheySayAdminTest extends PHPUnit_Framework_TestCase {
delete_post_meta(2, 'transcript'); delete_post_meta(2, 'transcript');
_set_up_get_posts_response(array( $admin = $this->getMock('WhatDidTheySayAdmin', array('_get_transcript_posts'));
'posts_per_page' => 1, $admin->_import_chunk_size = 1;
'meta_key' => 'transcript'
), array());
$this->assertEquals(false, $admin->import_transcripts('en')); $admin->expects($this->once())->method('_get_transcript_posts')->will($this->returnValue(array()));
$this->assertEquals(0, $admin->import_transcripts('en'));
} }
function providerTestCleanChild() { function providerTestCleanChild() {

View File

@ -23,6 +23,8 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
top.console
*/ */
foreach (glob(dirname(__FILE__) . '/classes/*.inc') as $__file) { require_once($__file); } foreach (glob(dirname(__FILE__) . '/classes/*.inc') as $__file) { require_once($__file); }