Currently the config provided by this module adds some unused values like form_build_id, form_token, ...
Also cron_last_run is a value that should not be stored in config, but state is a better place for this.
Third, the config schema is currently incorrect and the module uses some dynamic config properties.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

arrubiu created an issue. See original summary.

temkin’s picture

Looks like State API is a better fit for that - https://www.drupal.org/docs/8/api/state-api/overview

So, use State API to store information that is okay to lose along with the database. Think: CSRF tokens, tracking when something non-critical last happened …

I'll try to contribute a patch for that if time permits.

temkin’s picture

Status: Active » Needs review
StatusFileSize
new3.04 KB

Patch attached.

jeroent’s picture

Status: Needs review » Needs work
+++ b/src/Module/Config/ConfigHandler.php
@@ -12,23 +12,6 @@ namespace Drupal\db_maintenance\Module\Config;
-  /**
-   * Returns last cron run.
-   */
-  public static function getCronLastRun() {
-    $val = \Drupal::config('db_maintenance.settings')->get('cron_last_run');
-    return $val;
-  }
-
-  /**
-   * Sets last cron run.
-   */
-  public static function setCronLastRun($value) {
-    $config = \Drupal::configFactory()->getEditable('db_maintenance.settings');
-    $config->set('cron_last_run', $value);
-    $config->save();
-  }
-

I'm not really a fan of this ConfigHandler class, but since it exists, people could extend or use this in their own custom codes. Making this a BC break.

So the change with the least disruption would be to replace the config service with the state service in those 2 methods.

jeroent’s picture

Also, this probably needs an update hook to remove this unused config value for users who have this module currently installed.

jeroent’s picture

Title: Remove last cron from conf? » Cleanup config and improve schema
Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new5.73 KB

It looks like there are some more problems with the current config. Updated the IS.

Patch attached removes the unused config values like form_build_id_form_token, .... The config schema is updated so table_list now is also recognized by the config manager.

And I provided an upgrade path to fix config for existing sites.

thejimbirch’s picture

The patch applies cleanly, and config defaults for all the options in the settings.

cron_frequency: 604800
use_time_interval: true
time_interval_start: '01:30'
time_interval_end: '02:30'
all_tables: false
write_log: true
table_list:
  default:
    table_name:table_name
    table_name:table_name
    etc
_core:
  default_config_hash: hash

Not setting as RTBC because I didn't test the update hook. I applied patch on a new installation.

Thanks!

orkutmuratyilmaz’s picture

Status: Needs review » Reviewed & tested by the community

Hello all,

I've tried the patch #6 on 3 different installations and it worked so smooth. Thank you @JeroenT for the patch.

Also, @thejimbirch, I've tried running drush updb too. They worked well. So I'm setting this issue as RTBC.

Best,
Orkut

adamcadot’s picture

Version: 8.x-1.x-dev » 3.0.0-rc3
Status: Reviewed & tested by the community » Needs work

The patch does not apply to the latest version of the module.

orkutmuratyilmaz’s picture

Version: 3.0.0-rc3 » 3.0.x-dev
Assigned: Unassigned » orkutmuratyilmaz

orkutmuratyilmaz’s picture

Assigned: orkutmuratyilmaz » Unassigned
Status: Needs work » Needs review

@adamcadot can you check the latest 3.0.x-dev? I'm going to change the status of the issue as fixed, if it is okay.

adamcadot’s picture

Status: Needs review » Reviewed & tested by the community

Config exports as expected, and the update hook works without error.

orkutmuratyilmaz’s picture

Status: Reviewed & tested by the community » Fixed

@adamcot, thanks for the testing and validating too:)

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

adamcadot’s picture

@orkutmuratyilmaz Can we get this into a new RC?

orkutmuratyilmaz’s picture

New RC is released, thanks for reminding.

adamcadot’s picture

Status: Fixed » Closed (fixed)

Cheers, thanks for cleaning up these multi-year-long issues!