Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Save history isn't working #404

Merged
merged 4 commits into from
Sep 4, 2024
Merged
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
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
Loading