| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- <?php
- namespace cx_newsletter;
- use \get_option;
- use \update_option;
- use \delete_option;
- use \exception;
- class database_versions_manager {
- public function get_installed() : ?int {
- $version = get_option($this->get_database_version_name(), null);
- if ($version === null) {
- return null;
- }
- $version = intval($version);
- if ($version === 0) {
- return null;
- }
- return $version;
- }
- public function is_installed() : bool {
- return $this->get_installed() !== null;
- }
- public function set_installed(?int $version) : void {
- if ($version === null) {
- delete_option($this->get_database_version_name());
- return;
- }
- if ($version <= 0) {
- throw new exception('Version must be greaten than 0.');
- }
-
- update_option($this->get_database_version_name(), strval($version));
- }
- private function get_database_version_name() : string {
- return 'cx_newsletter_database_version';
- }
- }
|