| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <?php
- namespace ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Reinstall\Pages;
- use MGProvision\Proxmox\v2\repository\ClusterResourcesRepository;
- use MGProvision\Proxmox\v2\repository\FileRepository;
- use MGProvision\Proxmox\v2\repository\StorageRepository;
- use ModulesGarden\ProxmoxAddon\App\Services\ApiService;
- use ModulesGarden\ProxmoxAddon\App\Services\Cloud\ProductService;
- use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Reinstall\Buttons\TemplateInstallButton;
- use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\DataTable\Column;
- use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\DataTable\DataProviders\Providers\ArrayDataProvider;
- use function ModulesGarden\Servers\ProxmoxCloudVps\Core\Helper\sl;
- trait TemplateTrait
- {
- use ApiService;
- use ProductService;
- public function initContent()
- {
- $this->setInternalAlertMessage("Select the template for reinstallation. If you proceed, all data located on the virtual machine will be lost.");
- $this->unsetShowTitle();
- //Update
- $this->addActionButton(new TemplateInstallButton());
- }
- protected function loadHtml()
- {
- //name
- $this->addColumn((new Column('name'))->setSearchable(true, "string")->setOrderable('ASC'));
- //description
- if($this->configuration()->isQemu()){
- $this->addColumn((new Column('description'))->setSearchable(true, "string"));
- }
- }
- public function replaceFieldName($key, $row)
- {
- return sl("lang")->abtr("template", $row[$key]);
- }
- protected function loadData()
- {
- $data = [];
- $fileRepository = new FileRepository();
- $vm = \ModulesGarden\ProxmoxAddon\Core\Helper\sl('Vm')->getVm();
- $nodes = [$vm->getNode()];
- //LXC
- if ($this->configuration()->isLxc())
- {
- $storageRepository = new StorageRepository();
- $storageRepository->findByNodes($nodes);
- $storageRepository->findEnabed();
- $storages = $storageRepository->fetchAsArray();
- $fileRepository->findByNodes($nodes)
- ->findByStorages($storages);
- $fileRepository->findByContent('vztmpl');
- foreach ($fileRepository->fetch() as $entity)
- {
- if ($this->configuration()->isPermissionOsTemplates() && !in_array($entity->getVolid(), $this->configuration()->getPermissionOsTemplates()))
- {
- continue;
- }
- $data[] = [
- "id" => $entity->getVolid(),
- "name" => $entity->getFriendlyName(),
- ];
- }
- }//KVM
- else
- {
- if ($this->configuration()->isQemu())
- {
- $clusterResurces = new ClusterResourcesRepository();
- $clusterResurces->findKvmTemplate();
- if (!$this->configuration()->isOsTemplatesInAllNodes())
- {
- $clusterResurces->findByNodes($vm->getNode());
- }
- foreach ($clusterResurces->fetchWithUniqueNames($vm->getNode()) as $entity)
- {
- if ($entity->isCustom() && !$entity->matchName($this->getWhmcsParamByKey("serviceid")))
- {
- continue;
- }
- if ($this->configuration()->isPermissionOsTemplates() && !in_array($entity->getName(), $this->configuration()->getPermissionOsTemplates()))
- {
- continue;
- }
- $id = "{$entity->getNode()}/{$entity->getVmid()}";
- $description = $entity->getVm()->config()['description'];
- if(!$description){
- $description = '-';
- }
- $data[] = [
- "id" => $id,
- "name" => $entity->getName(),
- 'description' => sl('lang')->abtr('template_desc' ,$description)
- ];
- }
- }
- }
- $dataProv = new ArrayDataProvider();
- $dataProv->setDefaultSorting("name", 'ASC');
- $dataProv->setData($data);
- $this->setDataProvider($dataProv);
- }
- }
|