add import processing
This commit is contained in:
parent
13d5e3b670
commit
8e5f1ce4bd
|
@ -38,6 +38,8 @@ class WhatDidTheySayAdmin {
|
|||
|
||||
var $is_ajax = false;
|
||||
|
||||
var $_import_chunk_size = 50;
|
||||
|
||||
/**
|
||||
* Initialize the admin interface.
|
||||
* @param WhatDidTheySay $what_did_they_say The WhatDidTheySay object to use for all transcript transactions.
|
||||
|
@ -549,6 +551,28 @@ class WhatDidTheySayAdmin {
|
|||
return $ok;
|
||||
}
|
||||
|
||||
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;
|
||||
foreach ($posts as $post) {
|
||||
if ($transcript = get_post_meta($post->ID, 'transcript', true)) {
|
||||
$approved_transcript_manager = new WDTSApprovedTranscript($post->ID);
|
||||
$approved_transcript_manager->save_transcript(array(
|
||||
'language' => $language_code,
|
||||
'transcript' => $transcript
|
||||
));
|
||||
|
||||
delete_post_meta($post->ID, 'transcript');
|
||||
|
||||
$modified++;
|
||||
}
|
||||
}
|
||||
if ($modified == 0) { $modified = false; }
|
||||
}
|
||||
return $modified;
|
||||
}
|
||||
|
||||
/** Handle data updates **/
|
||||
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
|
||||
require_once('PHPUnit/Framework.php');
|
||||
require_once('MockPress/mockpress.php');
|
||||
|
||||
require_once(dirname(__FILE__) . '/../classes/WhatDidTheySayAdmin.inc');
|
||||
require_once(dirname(__FILE__) . '/../classes/WDTSTranscriptClasses.inc');
|
||||
|
||||
class WhatDidTheySayAdminTest extends PHPUnit_Framework_TestCase {
|
||||
function setUp() {
|
||||
|
@ -78,6 +80,54 @@ class WhatDidTheySayAdminTest extends PHPUnit_Framework_TestCase {
|
|||
'approve_transcriptions' => true
|
||||
), get_usermeta(1, 'transcript_capabilities'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Integration.
|
||||
*/
|
||||
function testPerformImport() {
|
||||
$admin = new WhatDidTheySayAdmin();
|
||||
$admin->_import_chunk_size = 1;
|
||||
|
||||
wp_insert_user(array('ID' => 1));
|
||||
wp_set_current_user(1);
|
||||
|
||||
_set_user_capabilities('approve_transcriptions');
|
||||
|
||||
for ($i = 1; $i <= 2; ++$i) {
|
||||
wp_insert_post(array('ID' => $i));
|
||||
update_post_meta($i, "transcript", "this is my transcript");
|
||||
}
|
||||
|
||||
_set_up_get_posts_response(array(
|
||||
'posts_per_page' => 1,
|
||||
'meta_key' => 'transcript'
|
||||
), array(
|
||||
get_post(1)
|
||||
));
|
||||
|
||||
$this->assertEquals(1, $admin->import_transcripts('en'));
|
||||
|
||||
$this->assertEquals('', get_post_meta(1, "transcript", true));
|
||||
$this->assertEquals('this is my transcript', get_post_meta(2, "transcript", true));
|
||||
|
||||
$this->assertEquals(array(
|
||||
array(
|
||||
'language' => 'en',
|
||||
'transcript' => 'this is my transcript',
|
||||
'user_id' => 1,
|
||||
'key' => 0
|
||||
)
|
||||
), get_post_meta(1, 'approved_transcripts', true));
|
||||
|
||||
delete_post_meta(2, 'transcript');
|
||||
|
||||
_set_up_get_posts_response(array(
|
||||
'posts_per_page' => 1,
|
||||
'meta_key' => 'transcript'
|
||||
), array());
|
||||
|
||||
$this->assertEquals(false, $admin->import_transcripts('en'));
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in New Issue