Skip to content

Commit

Permalink
Fix: Save history isn't working (#404)
Browse files Browse the repository at this point in the history
  • Loading branch information
burhandodhy committed Sep 4, 2024
1 parent d00b294 commit 101f577
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
6 changes: 5 additions & 1 deletion assets/js/src/views/video-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,10 @@ var VideoEditView = BrightcoveView.extend({
this.model.set('custom_fields', custom);
this.model.set('custom', custom_fields);

const history = this.el.querySelector('.brightcove-change-history').value;
const historyJson = JSON.stringify(history.split('\n').map((line) => line.trim()));
this.model.set('_change_history', historyJson);

this.model
.save()
.done(function () {
Expand Down Expand Up @@ -572,7 +576,7 @@ var VideoEditView = BrightcoveView.extend({
history = JSON.parse(history);

_.each(history, function (item) {
historyStr += item.user + ' - ' + item.time + '\n';
historyStr += item + '\n';
});

if (historyStr !== '') {
Expand Down
25 changes: 8 additions & 17 deletions includes/admin/api/class-bc-admin-media-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,21 +204,12 @@ public function bc_ajax_update_video_or_playlist() {

// Build out history if it's supported
if ( $use_history ) {
$history = null;
if ( isset( $_POST['history'] ) ) {
$raw = wp_unslash( $_POST['history'] );
$history = json_decode( $raw, true );
}
if ( null === $history ) {
$history = array();
}
$history = isset( $_POST['history'] ) ? json_decode( wp_unslash( $_POST['history'] ), true ) : [];

$user = wp_get_current_user();
$history[] = array(
'user' => $user->user_login,
'time' => gmdate( 'Y-m-d H:i:s', time() ),
);
$user = wp_get_current_user();
$history = array_merge( array( sprintf( '%s - %s', $user->user_login, wp_date( 'Y-m-d H:i:s' ) ) ), $history );

$history = array_filter( $history );
$custom['_change_history'] = wp_json_encode( $history );
}

Expand Down Expand Up @@ -589,7 +580,7 @@ public function brightcove_media_query() {

// Get a list of videos.

for ( $i = 0; $i < $tries; $i ++ ) {
for ( $i = 0; $i < $tries; $i++ ) {
$results = $this->cms_api->video_list( $posts_per_page, $posts_per_page * ( $page - 1 ), $query_string, $bc_video_sort_field, true, $folder_id );

if ( ! is_wp_error( $results ) ) {
Expand Down Expand Up @@ -634,7 +625,7 @@ public function brightcove_media_query() {

$bc_accounts->set_current_account_by_id( $account_id );

for ( $i = 0; $i < $tries; $i ++ ) {
for ( $i = 0; $i < $tries; $i++ ) {
$results = $this->cms_api->playlist_list( $query );

if ( ! is_wp_error( $results ) ) {
Expand All @@ -654,7 +645,7 @@ public function brightcove_media_query() {

$bc_accounts->set_current_account_by_id( $account_id );

for ( $i = 0; $i < $tries; $i ++ ) {
for ( $i = 0; $i < $tries; $i++ ) {
$results = $this->experiences_api->get_experiences_by_account_id( $account_id );

if ( ! is_wp_error( $results ) ) {
Expand All @@ -672,7 +663,7 @@ public function brightcove_media_query() {
}

// Get a list of available custom fields
for ( $i = 0; $i < $tries; $i ++ ) {
for ( $i = 0; $i < $tries; $i++ ) {
$fields = $this->cms_api->video_fields();

if ( ! is_wp_error( $fields ) ) {
Expand Down

0 comments on commit 101f577

Please sign in to comment.