PluginProbe
seQura / 4.0.0
seQura v4.0.0
4.3.4 4.3.3 4.3.2 4.3.1 trunk 2.0.0 2.0.10 2.0.11 2.0.12 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 3.0.0 3.0.2 3.0.5 3.0.6 3.0.7 3.1.0 3.1.1 3.2.0 3.2.1 3.2.2 4.0.0 All 30 releases
sequra / src / Repositories / Migrations / class-migration-install-320.php

class-migration-install-320.php in seQura 4.0.0, at src/Repositories/Migrations/class-migration-install-320.php

88 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Post install migration for version 3.2.0 of the plugin.
4 *
5 * @package SeQura/WC
6 * @subpackage SeQura/WC/Repositories
7 */
8
9 namespace SeQura\WC\Repositories\Migrations;
10
11 use Exception;
12 use Throwable;
13 use SeQura\WC\Repositories\Repository;
14
15 /**
16 * Post install migration for version 3.2.0 of the plugin.
17 */
18 class Migration_Install_320 extends Migration {
19
20 /**
21 * Hook name.
22 *
23 * @var string
24 */
25 private $hook_name;
26
27 /**
28 * Entity repository.
29 *
30 * @var Repository
31 */
32 private $entity_repository;
33
34 /**
35 * Queue repository.
36 *
37 * @var Repository
38 */
39 private $queue_repository;
40
41 /**
42 * Constructor
43 */
44 public function __construct(
45 \wpdb $wpdb,
46 string $hook_name,
47 Repository $entity_repository,
48 Repository $queue_repository
49 ) {
50 parent::__construct( $wpdb );
51 $this->hook_name = $hook_name;
52 $this->entity_repository = $entity_repository;
53 $this->queue_repository = $queue_repository;
54 }
55
56 /**
57 * Get the plugin version when the changes were made.
58 */
59 public function get_version(): string {
60 return '3.2.0';
61 }
62
63 /**
64 * Run the migration.
65 *
66 * @throws Throwable|Critical_Migration_Exception
67 */
68 public function run(): void {
69 // Schedule indexing of the sequra_order table.
70 $args = array( $this->hook_name );
71 if ( ! \wp_next_scheduled( $this->hook_name, $args ) ) {
72 \wp_schedule_event( time(), 'hourly', $this->hook_name, $args );
73 }
74 // Index tables with almost no data or no data at all (sequra_entity, sequra_queue).
75 $repos = array(
76 $this->entity_repository,
77 $this->queue_repository,
78 );
79 foreach ( $repos as $repo ) {
80 foreach ( $repo->get_required_indexes() as $index ) {
81 if ( ! $repo->add_index( $index ) ) {
82 throw new Exception( 'Failed to add index ' . \sanitize_key( $index->name ) . ' to table ' . \sanitize_key( $repo->get_table_name() ) );
83 }
84 }
85 }
86 }
87 }
88