first commit

This commit is contained in:
2023-09-12 21:41:04 +02:00
commit 3361a7f053
13284 changed files with 2116755 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
<?php
namespace WPML\Upgrade\Commands;
abstract class AddPrimaryKeyToTable extends \WPML_Upgrade_Run_All {
/**
* @return string
*/
abstract protected function get_table();
/**
* @return string
*/
abstract protected function get_key_name();
/**
* @return array
*/
abstract protected function get_key_columns();
/**
* @var \WPML_Upgrade_Schema
*/
private $upgrade_schema;
/**
* @param array $args
*/
public function __construct( array $args ) {
$this->upgrade_schema = $args[0];
}
/**
* @return bool
*/
protected function run() {
$this->result = false;
if ( $this->upgrade_schema->does_table_exist( $this->get_table() ) ) {
if ( ! $this->upgrade_schema->does_key_exist( $this->get_table(), $this->get_key_name() ) ) {
$this->result = $this->upgrade_schema->add_primary_key( $this->get_table(), $this->get_key_columns() );
} else {
$this->result = true;
}
}
return $this->result;
}
}

View File

@@ -0,0 +1,45 @@
<?php
namespace WPML\Upgrade\Commands;
abstract class DropIndexFromTable extends \WPML_Upgrade_Run_All {
/**
* @return string
*/
abstract protected function get_table();
/**
* @return string
*/
abstract protected function get_index();
/**
* @var \WPML_Upgrade_Schema
*/
private $upgrade_schema;
/**
* @param array $args
*/
public function __construct( array $args ) {
$this->upgrade_schema = $args[0];
}
/**
* @return bool
*/
protected function run() {
$this->result = false;
if ( $this->upgrade_schema->does_table_exist( $this->get_table() ) ) {
if ( $this->upgrade_schema->does_index_exist( $this->get_table(), $this->get_index() ) ) {
$this->result = $this->upgrade_schema->drop_index( $this->get_table(), $this->get_index() );
} else {
$this->result = true;
}
}
return $this->result;
}
}

View File

@@ -0,0 +1,70 @@
<?php
/**
* Abstract class to upgrade a table by adding a column to it.
*
* @package WPML
*/
namespace WPML\Upgrade\Commands;
/**
* Class Add_Index_To_Table
*/
abstract class AddIndexToTable extends \WPML_Upgrade_Run_All {
/**
* Get table name.
*
* @return string
*/
abstract protected function get_table();
/**
* Get index name.
*
* @return string
*/
abstract protected function get_index();
/**
* Get index definition.
*
* @return string
*/
abstract protected function get_index_definition();
/**
* Upgrade schema.
*
* @var \WPML_Upgrade_Schema
*/
private $upgrade_schema;
/**
* Add_Index_To_Table constructor.
*
* @param array $args
*/
public function __construct( array $args ) {
$this->upgrade_schema = $args[0];
}
/**
* Run the table upgrade.
*
* @return bool
*/
protected function run() {
$this->result = false;
if ( $this->upgrade_schema->does_table_exist( $this->get_table() ) ) {
if ( ! $this->upgrade_schema->does_index_exist( $this->get_table(), $this->get_index() ) ) {
$this->result = $this->upgrade_schema->add_index( $this->get_table(), $this->get_index(), $this->get_index_definition() );
} else {
$this->result = true;
}
}
return $this->result;
}
}

View File

@@ -0,0 +1,100 @@
<?php
/**
* Abstract class to upgrade a table by adding a column to it.
*
* @package WPML
*/
/**
* Class WPML_Upgrade_Add_Column_To_Table
*/
abstract class WPML_Upgrade_Add_Column_To_Table implements IWPML_Upgrade_Command {
/**
* Get table name.
*
* @return string
*/
abstract protected function get_table();
/**
* Get column name.
*
* @return string
*/
abstract protected function get_column();
/**
* Get column definition.
*
* @return string
*/
abstract protected function get_column_definition();
/**
* Upgrade schema.
*
* @var WPML_Upgrade_Schema
*/
private $upgrade_schema;
/**
* WPML_Upgrade_Add_Column_To_Table constructor.
*
* @param array $args Arguments.
*/
public function __construct( array $args ) {
$this->upgrade_schema = $args[0];
}
/**
* Run the table upgrade.
*
* @return bool
*/
private function run() {
if ( $this->upgrade_schema->does_table_exist( $this->get_table() ) ) {
if ( ! $this->upgrade_schema->does_column_exist( $this->get_table(), $this->get_column() ) ) {
$this->upgrade_schema->add_column( $this->get_table(), $this->get_column(), $this->get_column_definition() );
}
}
return true;
}
/**
* Run in admin.
*
* @return bool
*/
public function run_admin() {
return $this->run();
}
/**
* Run in ajax.
*
* @return bool
*/
public function run_ajax() {
return $this->run();
}
/**
* Run in frontend.
*
* @return bool
*/
public function run_frontend() {
return $this->run();
}
/**
* Get upgrade results.
*
* @return bool
*/
public function get_results() {
return true;
}
}