v1.0.0.1
StocketBase
- <?php
-
- declare(strict_types=1);
-
- if (count(get_included_files()) === 1) {
- http_response_code(403);
- exit;
- }
-
- $productId = (int) ($_POST['product_id'] ?? 0);
- $versionId = (int) ($_POST['version_id'] ?? 0);
-
- if ($productId <= 0 || $versionId <= 0) {
- return ['We couldn\'t find that version.', 'error', null];
- }
-
- $statement = Database::site()->prepare('SELECT created_by, deleted_at FROM products WHERE id = :id LIMIT 1');
- $statement->execute(['id' => $productId]);
- $product = $statement->fetch();
-
- if (!$product || $product['deleted_at'] !== null) {
- return ['We couldn\'t find that product.', 'error', null];
- }
-
- $isOwner = (int) $product['created_by'] === (int) $currentUser['id'];
- if (!$isOwner && !Auth::hasRoleAtLeast(Auth::ROLE_STORE_OWNER)) {
- return ['You don\'t have access to this product\'s history.', 'error', null];
- }
-
- if (!ProductVersions::restore($productId, $versionId, (int) $currentUser['id'], (string) $currentUser['display_name'])) {
- return ['We couldn\'t find that version.', 'error', null];
- }
-
- ActivityLog::record('product.restore_version', 'product', $productId, 'version #' . $versionId);
-
- return ['Earlier version restored.', 'success', $productId];
-