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\Component\Security\Http\Attribute\CurrentUser;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\Security\Core\Exception\UserNotFoundException;
|
use Symfony\Component\Security\Core\Exception\UserNotFoundException;
|
||||||
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||||
|
|
||||||
|
|
||||||
class HookController extends AbstractController
|
class HookController extends AbstractController
|
||||||
|
@ -405,45 +406,70 @@ class HookController extends AbstractController
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[Route('api/wordpress/plugin/stats', name: 'api_wordpress_plugin_stats', methods: ['GET'])]
|
#[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
|
||||||
{
|
{
|
||||||
|
$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([
|
return $this->json([
|
||||||
'Success' => true,
|
'Success' => true,
|
||||||
'ErrorCode' => 0,
|
'ErrorCode' => 0,
|
||||||
'ErrorMessage' => '',
|
'ErrorMessage' => '',
|
||||||
'Result' => [
|
'Result' => [
|
||||||
'version' => '1.0.0',
|
'version' => $version,
|
||||||
'plugin_name' => 'Hesabix WordPress Plugin',
|
'plugin_name' => 'Hesabix: WooCommerce',
|
||||||
'description' => 'پلاگین حسابیکس برای وردپرس',
|
'description' => 'پلاگین حسابیکس برای وردپرس',
|
||||||
'author' => 'Hesabix Team',
|
'author' => 'Mohammad Rzai',
|
||||||
'last_update' => '2024-01-15',
|
'author_url' => 'https://pirouz.xyz',
|
||||||
|
'last_update' => $lastUpdate,
|
||||||
'compatibility' => [
|
'compatibility' => [
|
||||||
'wordpress' => '5.0+',
|
'wordpress' => '5.0+',
|
||||||
'php' => '7.4+'
|
'php' => '7.4+'
|
||||||
],
|
],
|
||||||
'download_url' => 'https://hesabix.ir/plugins/wordpress-plugin-latest.zip',
|
'download_url' => $downloadUrl,
|
||||||
'changelog' => [
|
'changelog' => [
|
||||||
'1.0.0' => [
|
$version => [
|
||||||
'date' => '2024-01-15',
|
'date' => $lastUpdate,
|
||||||
'changes' => [
|
'changes' => preg_split('/\r\n|\n|\r/', $description),
|
||||||
'انتشار نسخه اولیه',
|
|
||||||
'اتصال به API حسابیکس',
|
|
||||||
'مدیریت فاکتورها',
|
|
||||||
'همگامسازی دادهها'
|
|
||||||
]
|
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
'statistics' => [
|
// 'statistics' => [
|
||||||
'total_installations' => 1250,
|
// 'total_installations' => 1250,
|
||||||
'active_installations' => 1180,
|
// 'active_installations' => 1180,
|
||||||
'total_downloads' => 3500,
|
// 'total_downloads' => 3500 + $downloadCount,
|
||||||
'average_rating' => 4.8,
|
// 'average_rating' => 4.8,
|
||||||
'support_tickets' => 45
|
// '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