| @@ -2,9 +2,9 @@ | ||
| 2 | 2 | |
| 3 | 3 | namespace Elementor\Modules\Variables\Storage; |
| 4 | 4 | |
| 5 | 5 | use Elementor\Core\Kits\Documents\Kit; |
| 6 | -use Elementor\Modules\AtomicWidgets\Utils\Utils; | |
| 6 | +use Elementor\Modules\AtomicWidgets\Utils; | |
| 7 | 7 | use Elementor\Modules\Variables\Storage\Exceptions\DuplicatedLabel; |
| 8 | 8 | use Elementor\Modules\Variables\Storage\Exceptions\RecordNotFound; |
| 9 | 9 | use Elementor\Modules\Variables\Storage\Exceptions\VariablesLimitReached; |
| 10 | 10 | use Elementor\Modules\Variables\Storage\Exceptions\FatalError; |
| @@ -15,8 +15,11 @@ | ||
| 15 | 15 | exit; // Exit if accessed directly. |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | class Repository { |
| 19 | + const TOTAL_VARIABLES_COUNT = 100; | |
| 20 | + const FORMAT_VERSION_V1 = 1; | |
| 21 | + const VARIABLES_META_KEY = '_elementor_global_variables'; | |
| 19 | 22 | private Kit $kit; |
| 20 | 23 | |
| 21 | 24 | public function __construct( Kit $kit ) { |
| 22 | 25 | $this->kit = $kit; |
| @@ -35,9 +38,9 @@ | ||
| 35 | 38 | |
| 36 | 39 | ++$variables_in_use; |
| 37 | 40 | } |
| 38 | 41 | |
| 39 | - if ( Constants::TOTAL_VARIABLES_COUNT < $variables_in_use ) { | |
| 42 | + if ( self::TOTAL_VARIABLES_COUNT < $variables_in_use ) { | |
| 40 | 43 | throw new VariablesLimitReached( 'Total variables count limit reached' ); |
| 41 | 44 | } |
| 42 | 45 | } |
| 43 | 46 | |
| @@ -70,9 +73,9 @@ | ||
| 70 | 73 | return $db_record['data'] ?? []; |
| 71 | 74 | } |
| 72 | 75 | |
| 73 | 76 | public function load(): array { |
| 74 | - $db_record = $this->kit->get_json_meta( Constants::VARIABLES_META_KEY ); | |
| 77 | + $db_record = $this->kit->get_json_meta( static::VARIABLES_META_KEY ); | |
| 75 | 78 | |
| 76 | 79 | if ( is_array( $db_record ) && ! empty( $db_record ) ) { |
| 77 | 80 | return $db_record; |
| 78 | 81 | } |
| @@ -338,9 +341,9 @@ | ||
| 338 | 341 | $id = $operation['id']; |
| 339 | 342 | $variable_data = $operation['variable']; |
| 340 | 343 | |
| 341 | 344 | if ( ! isset( $db_record['data'][ $id ] ) ) { |
| 342 | - throw new RecordNotFound( 'Variable not found' ); | |
| 345 | + throw new \Elementor\Modules\Variables\Storage\Exceptions\RecordNotFound( 'Variable not found' ); | |
| 343 | 346 | } |
| 344 | 347 | |
| 345 | 348 | $updated_fields = $this->extract_from( $variable_data, [ 'label', 'value', 'order' ] ); |
| 346 | 349 | $updated_variable = array_merge( $db_record['data'][ $id ], $updated_fields ); |
| @@ -454,9 +457,9 @@ | ||
| 454 | 457 | } |
| 455 | 458 | |
| 456 | 459 | ++$db_record['watermark']; |
| 457 | 460 | |
| 458 | - if ( $this->kit->update_json_meta( Constants::VARIABLES_META_KEY, $db_record ) ) { | |
| 461 | + if ( $this->kit->update_json_meta( static::VARIABLES_META_KEY, $db_record ) ) { | |
| 459 | 462 | return $db_record['watermark']; |
| 460 | 463 | } |
| 461 | 464 | |
| 462 | 465 | return false; |
| @@ -477,9 +480,9 @@ | ||
| 477 | 480 | private function get_default_meta(): array { |
| 478 | 481 | return [ |
| 479 | 482 | 'data' => [], |
| 480 | 483 | 'watermark' => 0, |
| 481 | - 'version' => Constants::FORMAT_VERSION_V1, | |
| 484 | + 'version' => self::FORMAT_VERSION_V1, | |
| 482 | 485 | ]; |
| 483 | 486 | } |
| 484 | 487 | |
| 485 | 488 | private function get_next_order( array $list_of_variables ): int { |