From 72c8b03ff7c9de33a11f4fc3bd04f1e2e7efb946 Mon Sep 17 00:00:00 2001 From: vnmedeiros Date: Mon, 10 Apr 2023 13:59:04 -0300 Subject: [PATCH] chore: remove `@session_start()` --- ...ass-tainacan-rest-exporters-controller.php | 39 ++++---- ...ass-tainacan-rest-importers-controller.php | 8 -- src/classes/importer/import.php | 89 ------------------- tests/test-importer.php | 9 ++ 4 files changed, 25 insertions(+), 120 deletions(-) delete mode 100644 src/classes/importer/import.php diff --git a/src/classes/api/endpoints/class-tainacan-rest-exporters-controller.php b/src/classes/api/endpoints/class-tainacan-rest-exporters-controller.php index 08a368eac..c164fd950 100644 --- a/src/classes/api/endpoints/class-tainacan-rest-exporters-controller.php +++ b/src/classes/api/endpoints/class-tainacan-rest-exporters-controller.php @@ -19,17 +19,10 @@ class REST_Exporters_Controller extends REST_Controller { */ public function __construct() { $this->rest_base = 'exporters'; - if (session_status() == PHP_SESSION_NONE) { - @session_start(); // @ avoids Warnings when running phpunit tests - } parent::__construct(); add_action('init', array(&$this, 'init_objects'), 11); } - public function __destruct() { - session_write_close(); - } - /** * Initialize objects after post_type register */ @@ -95,24 +88,24 @@ class REST_Exporters_Controller extends REST_Controller { } - /** - * - * @param \WP_REST_Request $request - * - * @return bool|\WP_Error - * @throws \Exception - */ - public function export_permissions_check($request) { - return true; - } + /** + * + * @param \WP_REST_Request $request + * + * @return bool|\WP_Error + * @throws \Exception + */ + public function export_permissions_check($request) { + return true; + } - public function get_registered_exporters() { - global $Tainacan_Exporter_Handler; - $exporters = $Tainacan_Exporter_Handler->get_registered_exporters(); - return new \WP_REST_Response( $exporters, 200 ); - } + public function get_registered_exporters() { + global $Tainacan_Exporter_Handler; + $exporters = $Tainacan_Exporter_Handler->get_registered_exporters(); + return new \WP_REST_Response( $exporters, 200 ); + } - /** + /** * Creates a new instance of the desired exporter and returns its ID * * @param \WP_REST_Request $request diff --git a/src/classes/api/endpoints/class-tainacan-rest-importers-controller.php b/src/classes/api/endpoints/class-tainacan-rest-importers-controller.php index 6a8d0afaa..dc15c3d33 100644 --- a/src/classes/api/endpoints/class-tainacan-rest-importers-controller.php +++ b/src/classes/api/endpoints/class-tainacan-rest-importers-controller.php @@ -11,8 +11,6 @@ use Tainacan\Entities; * * */ class REST_Importers_Controller extends REST_Controller { - private $collections_repository; - private $collection; /** * REST_Importers_Controller constructor. @@ -20,15 +18,9 @@ class REST_Importers_Controller extends REST_Controller { */ public function __construct(){ $this->rest_base = 'importers'; - if (session_status() == PHP_SESSION_NONE) { - @session_start(); // @ avoids Warnings when running phpunit tests - } parent::__construct(); } - public function __destruct() { - session_write_close(); - } /** * Register the collections route and their endpoints */ diff --git a/src/classes/importer/import.php b/src/classes/importer/import.php deleted file mode 100644 index 0be1f3c3b..000000000 --- a/src/classes/importer/import.php +++ /dev/null @@ -1,89 +0,0 @@ -parse_args($argv); - $this->run(); - - } - - /** - * parse args from and set the attributs - * 1 - Old Tainacan url (required) - */ - function parse_args($argv) { - - if (!is_array($argv)) - return; - - - if (isset($argv[1])) { - - if (filter_var($argv[1], FILTER_VALIDATE_URL)) { - $this->url = $argv[1]; - } - - } - - if (isset($argv[2])) { - - if (is_numeric($argv[2])) { - $this->step = $argv[2]; - } else { - $this->run = ''; - } - - } - - } - - /** - * echo message in prompt line - */ - function log($msg) { - - echo $msg . PHP_EOL; - - } - - function run() { - - $start = $partial = microtime(true); - - // Avoid warnings - $_SERVER['SERVER_PROTOCOL'] = "HTTP/1.1"; - $_SERVER['REQUEST_METHOD'] = "GET"; - - define( 'WP_USE_THEMES', false ); - define( 'SHORTINIT', false ); - // require( dirname(__FILE__) . '/../../../../wp-blog-header.php' ); - - $old_tainacan = new \Tainacan\Importer\Old_Tainacan(); - $id = $old_tainacan->get_id(); - - $_SESSION['tainacan_importer'][$id]->set_url($this->url); - - while (!$_SESSION['tainacan_importer'][$id]->is_finished()){ - $_SESSION['tainacan_importer'][$id]->run(); - } - - $scripttime = microtime(true) - $start; - - $this->log("=========================================================="); - $this->log("=========================================================="); - $this->log("=== Fim do script. Tempo de execução {$scripttime}s"); - $this->log("=========================================================="); - $this->log("=========================================================="); - - } -} - -$x = new ScriptTainacanOld($argv); \ No newline at end of file diff --git a/tests/test-importer.php b/tests/test-importer.php index f1c8d6283..98d1230c2 100644 --- a/tests/test-importer.php +++ b/tests/test-importer.php @@ -30,6 +30,15 @@ class ImporterTests extends TAINACAN_UnitTestCase { this->assertEquals( $collection->get_id(), $_SESSION['tainacan_importer'][$id]->collection->get_id() ); }*/ + public function __construct(){ + parent::__construct(); + @session_start(); + } + + public function __destruct() { + session_write_close(); + } + public function test_automapping_old_tainacan() { //$Tainacan_Items = \Tainacan\Repositories\Items::get_instance();