Skip to content
Merged
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
56 changes: 27 additions & 29 deletions php/class-connect.php
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,14 @@ public function history( $days = 1 ) {
uksort(
$history[ $plan ],
static function ( $a, $b ) {
return strtotime( $a ) > strtotime( $b );
$a = strtotime( $a );
$b = strtotime( $b );

if ( $a === $b ) {
return 0;
}

return $a > $b ? - 1 : 1;
}
);
$history[ $plan ] = array_slice( $history[ $plan ], -30 );
Expand All @@ -473,38 +480,29 @@ static function ( $a, $b ) {
public function upgrade_settings( $previous_version, $new_version ) {
// Check if we need to upgrade the history.
if ( version_compare( $previous_version, '3.1.0', '<' ) ) {
$history = get_option( self::META_KEYS['history'], array() );
$plan = false;

if ( ! empty( $this->usage['plan'] ) ) {
$plan = $this->usage['plan'];
} elseif ( ! empty( $this->credentials['cloud_name'] ) ) {
$plan = $this->credentials['cloud_name'];
}

// Check whether history has migrated.
if ( ! empty( $plan ) && ! empty( $history[ $plan ] ) ) {
return;
}

// Fix history.
$new_history = array();
foreach ( $history as $date => $data ) {
$new_history[ $plan ][ $date ] = $data;
}
add_action(
'cloudinary_ready',
function () {
$history = get_option( self::META_KEYS['history'], array() );
$plan = false;

if ( ! empty( $this->usage['plan'] ) ) {
$plan = $this->usage['plan'];
} elseif ( ! empty( $this->credentials['cloud_name'] ) ) {
$plan = $this->credentials['cloud_name'];
}

foreach ( $new_history as &$data ) {
uksort(
$data,
static function ( $a, $b ) {
return strtotime( $a ) < strtotime( $b );
// Check whether history has migrated.
if ( ! empty( $plan ) && ! empty( $history[ $plan ] ) ) {
return;
}
);

$data = array_reverse( array_slice( $data, 0, 30 ) );
}
// Cleanup history.
$new_history = array();

update_option( self::META_KEYS['history'], $new_history, false );
update_option( self::META_KEYS['history'], $new_history, false );
}
);
}
}

Expand Down