Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions admin/AmazonAI-Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -582,8 +582,6 @@ public function create_tim_limitless_installkey(){
$responseData=json_decode($response, TRUE);
update_option( TIM_LIMITLESS_INSTALLKEY, $responseData["installkey"]);
update_option(TIM_LIMITLESS_VIEWKEY,$responseData["viewkey"]);
$polly_service = new AmazonAI_PollyService();
$polly_service->tim_limitless_ajax_bulk_synthesize(false);
}
else{
$this->show_error_notice("notice-error", "Can't connect to tim limitless! Please contact Tim Support support@thetimmedia.com");
Expand Down
60 changes: 32 additions & 28 deletions admin/AmazonAI-PollyService.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,42 +100,46 @@ private function update_tim_limitless_post_hash($text,$post_meta_field,$installk
update_post_meta( $post_id, $post_meta_field, $responseData['postHash']);
}
}
public function tim_limitless_ajax_bulk_synthesize_enable_polly(){
header('Content-type: application/json');
if($this->tim_limitless_ajax_bulk_synthesize(true)){
$result="success";
}else{
$result="failure";
}
echo wp_json_encode(
array(
"status"=>$result
)
);
wp_die();
}

public function tim_limitless_ajax_bulk_synthesize($enable_polly){
public function tim_limitless_ajax_bulk_update(){
header('Content-type: application/json');
$common = new AmazonAI_Common();
$common->init();
$post_ids = get_posts(array(
'fields' => 'ids', // Only get post IDs
'posts_per_page' => -1
));
$isError = false;
foreach ($post_ids as $id){
try{
$this->save_post_tim_limitless($common,$id);
if($enable_polly){
update_post_meta( $id, 'amazon_polly_enable', 1);
}
}
catch (Exception $e){
error_log("bulk update error for post_id:".$id." error:".$e->getMessage(), 0);
$isError=true;
}
$index = $_POST['index'];
$num_posts = sizeof($post_ids);
if($num_posts-1<$index){
echo wp_json_encode(
array(
"status"=>"done",
"index"=>$index,
"num_posts"=>$num_posts
)
);
wp_die();
return;
}
return !$isError;
try{
$this->save_post_tim_limitless($common,$post_ids[index]->id);
update_post_meta( $post_ids[index]->id, 'amazon_polly_enable', 1);

}
catch (Exception $e){
error_log("bulk update error for post_id:".$post_ids[index]->id." error:".$e->getMessage(), 0);
}

echo wp_json_encode(
array(
"status"=>"not_done",
"index"=>$index,
"num_posts"=>$num_posts
)
);
wp_die();

}

/**
Expand Down
4 changes: 4 additions & 0 deletions admin/css/amazonpolly-admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@
font-size: .8em;
color: blue;
}

#successLabel{
margin-left: 72px;
}
15 changes: 9 additions & 6 deletions admin/js/tim_limitless-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@
timDiv.insertBefore(div, timDiv.childNodes[0]);
}

function updateAllPosts() {
function updateAllPosts(index) {

$.ajax({
type: 'POST',
url: ajaxurl,
data: {
action: 'tim_limitless_bulk_update',
index:index
},
dataType: "json",
beforeSend: function() {
Expand All @@ -51,12 +52,14 @@
complete: function() {
},
success: function( response ) {
showLoader(false);
var label = document.getElementById("successLabel");
if(response.status=="success"){
label.innerText="All posts were updated successfully.";
if(response.status=="not_done"){
response.index++;
label.innerText = response.index + " of " +response.num_posts +" posts were updated.";
updateAllPosts(response.index);
}else{
label.innerText="Update finished. Some posts failed to update.";
showLoader(false);
label.innerText="All posts were updated";
}
}
}).fail(function (response) {
Expand All @@ -75,7 +78,7 @@
$( '#tim_limitless_update_all' ).click(
function(){
addLoaderToPage();
updateAllPosts();
updateAllPosts(0);
}
);

Expand Down
2 changes: 1 addition & 1 deletion includes/class-amazonpolly.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ private function define_admin_hooks() {
$this->loader->add_action( 'before_delete_post', $common, 'delete_post' );
$this->loader->add_action( 'wp_ajax_polly_transcribe', $polly_service, 'ajax_bulk_synthesize' );
if($common->is_trinity_connected()){
$this->loader->add_action( 'wp_ajax_tim_limitless_bulk_update', $polly_service, 'tim_limitless_ajax_bulk_synthesize_enable_polly' );
$this->loader->add_action( 'wp_ajax_tim_limitless_bulk_update', $polly_service, 'tim_limitless_ajax_bulk_update' );
}


Expand Down