imports working
This commit is contained in:
parent
89339c7d3b
commit
b16ce4daae
@ -38,7 +38,7 @@ class WhatDidTheySayAdmin {
|
||||
|
||||
var $is_ajax = false;
|
||||
|
||||
var $_import_chunk_size = 50;
|
||||
var $_import_chunk_size = 20;
|
||||
|
||||
/**
|
||||
* Initialize the admin interface.
|
||||
@ -321,6 +321,17 @@ class WhatDidTheySayAdmin {
|
||||
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") {
|
||||
$this->read_language_file();
|
||||
wp_enqueue_style('wdts-admin', plugin_dir_url(dirname(__FILE__)) . 'css/wdts-admin.css');
|
||||
@ -551,25 +562,31 @@ class WhatDidTheySayAdmin {
|
||||
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) {
|
||||
$modified = false;
|
||||
$posts = get_posts(array('posts_per_page' => $this->_import_chunk_size, 'meta_key' => 'transcript'));
|
||||
if (!empty($posts)) {
|
||||
$modified = 0;
|
||||
$post_ids = $this->_get_transcript_posts();
|
||||
if (!empty($post_ids)) {
|
||||
$modified = 0;
|
||||
foreach ($posts as $post) {
|
||||
if ($transcript = get_post_meta($post->ID, 'transcript', true)) {
|
||||
$approved_transcript_manager = new WDTSApprovedTranscript($post->ID);
|
||||
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(
|
||||
'language' => $language_code,
|
||||
'transcript' => $transcript
|
||||
));
|
||||
|
||||
delete_post_meta($post->ID, 'transcript');
|
||||
|
||||
$modified++;
|
||||
}
|
||||
delete_post_meta($post_id, 'transcript');
|
||||
|
||||
$modified++;
|
||||
|
||||
if ($modified >= $this->_import_chunk_size) { break; }
|
||||
}
|
||||
if ($modified == 0) { $modified = false; }
|
||||
}
|
||||
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) {
|
||||
$this->is_ajax = true;
|
||||
|
||||
@ -1052,6 +1079,17 @@ class WhatDidTheySayAdmin {
|
||||
$nonce = wp_create_nonce('what-did-they-say');
|
||||
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');
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -85,7 +85,7 @@ class WhatDidTheySayAdminTest extends PHPUnit_Framework_TestCase {
|
||||
* Integration.
|
||||
*/
|
||||
function testPerformImport() {
|
||||
$admin = new WhatDidTheySayAdmin();
|
||||
$admin = $this->getMock('WhatDidTheySayAdmin', array('_get_transcript_posts'));
|
||||
$admin->_import_chunk_size = 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");
|
||||
}
|
||||
|
||||
_set_up_get_posts_response(array(
|
||||
'posts_per_page' => 1,
|
||||
'meta_key' => 'transcript'
|
||||
), array(
|
||||
get_post(1)
|
||||
));
|
||||
|
||||
$admin->expects($this->once())->method('_get_transcript_posts')->will($this->returnValue(array(1,2)));
|
||||
$this->assertEquals(1, $admin->import_transcripts('en'));
|
||||
|
||||
$this->assertEquals('', get_post_meta(1, "transcript", true));
|
||||
@ -121,12 +115,12 @@ class WhatDidTheySayAdminTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
delete_post_meta(2, 'transcript');
|
||||
|
||||
_set_up_get_posts_response(array(
|
||||
'posts_per_page' => 1,
|
||||
'meta_key' => 'transcript'
|
||||
), array());
|
||||
$admin = $this->getMock('WhatDidTheySayAdmin', array('_get_transcript_posts'));
|
||||
$admin->_import_chunk_size = 1;
|
||||
|
||||
$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() {
|
||||
|
@ -23,6 +23,8 @@ GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
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); }
|
||||
|
Loading…
Reference in New Issue
Block a user