-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:cdek-it/wordpress
- Loading branch information
Showing
21 changed files
with
1,474 additions
and
305 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace { | ||
defined('ABSPATH') or exit; | ||
} | ||
|
||
namespace Cdek\Actions\Schedule { | ||
|
||
use Cdek\Contracts\TaskContract; | ||
use Cdek\Model\TaskOutputData; | ||
|
||
class CollectOrders extends TaskContract | ||
{ | ||
private const ORDERS_LIMIT = 10000; | ||
|
||
public static function getName(): string | ||
{ | ||
return 'collect-orphaned-orders'; | ||
} | ||
|
||
public function start(): void | ||
{ | ||
$query = new \WC_Order_Query( | ||
[ | ||
'orderby' => 'id', | ||
'order' => 'ASC', | ||
'paginate' => true, | ||
'limit' => self::ORDERS_LIMIT, | ||
'return' => 'ids', | ||
], | ||
); | ||
|
||
for ($page = 1, $maxPages = 1; $page <= $maxPages; $page++) { | ||
$query->set('page', $page); | ||
$result = $query->get_orders(); | ||
|
||
$maxPages = $result->max_num_pages; | ||
|
||
$response = $this->cdekCoreApi->sendTaskData( | ||
$this->taskId, | ||
new TaskOutputData( | ||
'success', | ||
[ | ||
'orders' => array_map( | ||
static fn($order) => (string)$order, | ||
$result->orders, | ||
) | ||
], | ||
$page, | ||
$maxPages | ||
) | ||
); | ||
|
||
$this->initData($response); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
|
||
namespace { | ||
|
||
defined('ABSPATH') or exit; | ||
} | ||
|
||
namespace Cdek\Actions\Schedule { | ||
|
||
use Cdek\Contracts\TaskContract; | ||
use Cdek\Exceptions\CdekApiException; | ||
use Cdek\Exceptions\CdekScheduledTaskException; | ||
use Cdek\Model\TaskOutputData; | ||
use Cdek\Model\OrderMetaData; | ||
use Cdek\Model\Validate; | ||
|
||
class ReindexOrders extends TaskContract | ||
{ | ||
public function __construct(string $taskId) | ||
{ | ||
parent::__construct($taskId); | ||
$this->initTaskData(); | ||
} | ||
|
||
public static function getName(): string | ||
{ | ||
return 'restore-order-uuids'; | ||
} | ||
|
||
/** | ||
* @return void | ||
* @throws CdekApiException | ||
* @throws CdekScheduledTaskException | ||
* @throws \JsonException | ||
*/ | ||
public function start(): void | ||
{ | ||
if (empty($this->getTaskMeta())) { | ||
throw new CdekScheduledTaskException( | ||
'[CDEKDelivery] Failed to get orders meta info', | ||
'cdek_error.core.data', | ||
); | ||
} | ||
|
||
foreach ($this->getTaskMeta() as $arOrder) { | ||
OrderMetaData::updateMetaByOrderId( | ||
$arOrder['external_id'], | ||
[ | ||
'order_uuid' => $arOrder['id'], | ||
], | ||
); | ||
} | ||
|
||
$this->initData($this->cdekCoreApi->sendTaskData( | ||
$this->taskId, | ||
new TaskOutputData('success'), | ||
)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
namespace { | ||
defined('ABSPATH') or exit; | ||
} | ||
|
||
namespace Cdek\Cache | ||
{ | ||
|
||
use Cdek\Exceptions\CdekApiException; | ||
use Cdek\Loader; | ||
|
||
class FileCache | ||
{ | ||
private const CACHE_FILE_NAME = '.cache.php'; | ||
private static array $store; | ||
|
||
public static function getVars(): ?array | ||
{ | ||
if(!file_exists(Loader::getPluginPath() . DIRECTORY_SEPARATOR . self::CACHE_FILE_NAME)){ | ||
return null; | ||
} | ||
|
||
return self::$store[self::CACHE_FILE_NAME] ?? self::$store[self::CACHE_FILE_NAME] = require_once(Loader::getPluginPath() . DIRECTORY_SEPARATOR . self::CACHE_FILE_NAME); | ||
} | ||
|
||
/** | ||
* @param array|null $vars | ||
* | ||
* @return void | ||
* @throws CdekApiException | ||
*/ | ||
public static function putVars(?array $vars): void | ||
{ | ||
if($vars === null){ | ||
return; | ||
} | ||
|
||
if(file_exists(Loader::getPluginPath() . DIRECTORY_SEPARATOR . self::CACHE_FILE_NAME)){ | ||
if(!is_writable(Loader::getPluginPath() . DIRECTORY_SEPARATOR . self::CACHE_FILE_NAME)){ | ||
throw new CdekApiException('[CDEKDelivery] Failed check file rights', | ||
'cdek_error.cache.rights', | ||
['path' => Loader::getPluginPath() . DIRECTORY_SEPARATOR . self::CACHE_FILE_NAME], | ||
true); | ||
} | ||
}else{ | ||
if(!is_writable(Loader::getPluginPath())){ | ||
throw new CdekApiException('[CDEKDelivery] Failed check directory rights', | ||
'cdek_error.cache.rights', | ||
['path' => Loader::getPluginPath()], | ||
true); | ||
} | ||
} | ||
|
||
|
||
$logFile = fopen( Loader::getPluginPath() . DIRECTORY_SEPARATOR . self::CACHE_FILE_NAME, 'w+'); | ||
|
||
fwrite($logFile, '<?php return ' . var_export($vars, true) . ';' . PHP_EOL); | ||
fclose($logFile); | ||
} | ||
|
||
public static function clear(): void | ||
{ | ||
unlink(Loader::getPluginPath() . DIRECTORY_SEPARATOR . self::CACHE_FILE_NAME); | ||
} | ||
} | ||
} |
Oops, something went wrong.