Skip to content

Jobs options saving and UI inconsistencies #232

@AndisGrossteins

Description

@AndisGrossteins

Note: I've posted WordPress.org plugin support forum Multiple issues with version 5.5 but haven't received any responses, probably because I didn't mark it as a support request.

Describe the bug
When editing backup jobs, there are extra entries present in the backwpup_jobs option after deleting the two default and legacy jobs except for one. This is causing inconsistencies – in UI the job has database backup enabled but when running the job it doesn't backup database.

To Reproduce
Steps to reproduce the behavior:

  1. Install BackWPup and complete initial setup
  2. Wait for first backup to finish
  3. Create new backup job
  4. Check output from wp option get backwpup_jobs --format=json > backwpup_jobs.json

Expected behavior
Consistency between UI and saved data.

Desktop (please complete the following information):

  • OS: Windows 11
  • Browser Chrome 140.0.7339.208
  • WordPress version: 6.8.3
  • PHP version: 8.3.6

Additional context
I went to inspect and exported the jobs as JSON using wp-cli command:

wp option get backwpup_jobs --format=json > backwpup_jobs.json

There were two extra entries with only some options present at the end of JSON object. One of them has a "jobid": 4 which matches with entry before it and overrides the "type": ["FILE", "WPPLUGIN"] option from actual job entry but only in UI.

A sample from the exported JSON:

{
  "3": {
    "jobid": 4,
    "type": ["FILE", "DBDUMP", "WPPLUGIN"],
    /* {snip} */
  },
  "4": { "type": ["DBDUMP"], "activetype": "wpcron", "cron": "0 3 * * *" },
  "5": { "jobid": 4, "type": ["FILE", "DBDUMP", "WPPLUGIN"] }
}

Today I was able to reproduce the issue with a fresh install of BackWPup locally. After initial setup and completion of default job, when I create a new job, the UI shows two jobs but the backwpup_jobs option contains three entries with different jobid properties (1,2,3).

Screenshot of UI after adding new job and reloading page:
Image
Note that "Job ID 1" is not visible but present in the backwpup_jobs.

I've posted the JSON output in a gist: https://gist.github.com/AndisGrossteins/2e44f0b31841c2bdbbaf89a8717dc83a

There's something funky in how the option is updated around here:

$jobids = array_column( $jobs_options, 'jobid' );
$job_keys = array_keys( $jobs_options );
$job_index = array_search( $jobid, $jobids, true );
if ( false !== $job_index ) {
$job_key = $job_keys[ $job_index ];
} else {
// Prevent collision with existing keys.
$job_key = empty( $job_keys ) ? 0 : max( $job_keys ) + 1;
$jobs_options[ $job_key ] = [
'jobid' => $jobid,
];
}
$jobs_options[ $job_key ][ $option ] = $value;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions