update for Hooks
This commit is contained in:
parent
82d39dbb42
commit
36c2841011
|
@ -31,6 +31,7 @@ use Symfony\Component\HttpFoundation\JsonResponse;
|
|||
use Symfony\Component\Security\Http\Attribute\CurrentUser;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Security\Core\Exception\UserNotFoundException;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
|
||||
|
||||
class HookController extends AbstractController
|
||||
|
@ -405,45 +406,70 @@ class HookController extends AbstractController
|
|||
]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#[Route('api/wordpress/plugin/stats', name: 'api_wordpress_plugin_stats', methods: ['GET'])]
|
||||
public function api_wordpress_plugin_stats(): JsonResponse
|
||||
public function api_wordpress_plugin_stats(HttpClientInterface $httpClient): JsonResponse
|
||||
{
|
||||
return $this->json([
|
||||
'Success' => true,
|
||||
'ErrorCode' => 0,
|
||||
'ErrorMessage' => '',
|
||||
'Result' => [
|
||||
'version' => '1.0.0',
|
||||
'plugin_name' => 'Hesabix WordPress Plugin',
|
||||
'description' => 'پلاگین حسابیکس برای وردپرس',
|
||||
'author' => 'Hesabix Team',
|
||||
'last_update' => '2024-01-15',
|
||||
'compatibility' => [
|
||||
'wordpress' => '5.0+',
|
||||
'php' => '7.4+'
|
||||
],
|
||||
'download_url' => 'https://hesabix.ir/plugins/wordpress-plugin-latest.zip',
|
||||
'changelog' => [
|
||||
'1.0.0' => [
|
||||
'date' => '2024-01-15',
|
||||
'changes' => [
|
||||
'انتشار نسخه اولیه',
|
||||
'اتصال به API حسابیکس',
|
||||
'مدیریت فاکتورها',
|
||||
'همگامسازی دادهها'
|
||||
$apiUrl = 'https://source.hesabix.ir/api/v1/repos/morrning/hesabixWCPlugin/releases';
|
||||
|
||||
try {
|
||||
$response = $httpClient->request('GET', $apiUrl);
|
||||
$releases = $response->toArray();
|
||||
|
||||
if (empty($releases)) {
|
||||
return $this->json([
|
||||
'Success' => false,
|
||||
'ErrorCode' => 1,
|
||||
'ErrorMessage' => 'No releases found.',
|
||||
'Result' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
$latest = $releases[0];
|
||||
|
||||
$version = $latest['tag_name'];
|
||||
$description = $latest['body'];
|
||||
$lastUpdate = (new \DateTime($latest['published_at']))->format('Y-m-d');
|
||||
$downloadUrl = $latest['assets'][0]['browser_download_url'] ?? null;
|
||||
$downloadCount = $latest['assets'][0]['download_count'] ?? 0;
|
||||
|
||||
return $this->json([
|
||||
'Success' => true,
|
||||
'ErrorCode' => 0,
|
||||
'ErrorMessage' => '',
|
||||
'Result' => [
|
||||
'version' => $version,
|
||||
'plugin_name' => 'Hesabix: WooCommerce',
|
||||
'description' => 'پلاگین حسابیکس برای وردپرس',
|
||||
'author' => 'Mohammad Rzai',
|
||||
'author_url' => 'https://pirouz.xyz',
|
||||
'last_update' => $lastUpdate,
|
||||
'compatibility' => [
|
||||
'wordpress' => '5.0+',
|
||||
'php' => '7.4+'
|
||||
],
|
||||
'download_url' => $downloadUrl,
|
||||
'changelog' => [
|
||||
$version => [
|
||||
'date' => $lastUpdate,
|
||||
'changes' => preg_split('/\r\n|\n|\r/', $description),
|
||||
]
|
||||
]
|
||||
],
|
||||
'statistics' => [
|
||||
'total_installations' => 1250,
|
||||
'active_installations' => 1180,
|
||||
'total_downloads' => 3500,
|
||||
'average_rating' => 4.8,
|
||||
'support_tickets' => 45
|
||||
],
|
||||
// 'statistics' => [
|
||||
// 'total_installations' => 1250,
|
||||
// 'active_installations' => 1180,
|
||||
// 'total_downloads' => 3500 + $downloadCount,
|
||||
// 'average_rating' => 4.8,
|
||||
// 'support_tickets' => 45
|
||||
// ]
|
||||
]
|
||||
]
|
||||
]);
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->json([
|
||||
'Success' => false,
|
||||
'ErrorCode' => 2,
|
||||
'ErrorMessage' => 'Failed to fetch plugin release data.',
|
||||
'Result' => null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue