📁
SKYSHELL MANAGER
PHP v8.2.31
Create
Create
Path:
root
/
home
/
thevaxnx
/
nativize.com
/
staging
/
wp-includes
/
js
/
tinymce
/
themes
/
Name
Size
Perm
Actions
📁
inlite
-
0755
🗑️
🏷️
🔒
📁
modern
-
0755
🗑️
🏷️
🔒
📄
wp-links-opml.php
6.83 KB
0444
🗑️
🏷️
⬇️
✏️
🔒
Edit: CertificateRepository.php
<?php namespace App\Repository; use App\Entity\Certificate; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Persistence\ManagerRegistry; use Symfony\Component\Security\Core\User\UserInterface; /** * @extends ServiceEntityRepository<Certificate> * * @method Certificate|null find($id, $lockMode = null, $lockVersion = null) * @method Certificate|null findOneBy(array $criteria, array $orderBy = null) * @method Certificate[] findAll() * @method Certificate[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) */ class CertificateRepository extends ServiceEntityRepository { /** Certs synced by the cron more recently than this are skipped by getPotentialCertificatesForSync(). */ private const CRON_SYNC_GUARD_INTERVAL = '-24 hours'; public function __construct(ManagerRegistry $registry) { parent::__construct($registry, Certificate::class); } public function getAllPendingInstallation(UserInterface $user, int $maxCertificateInstallationAttempts): array { $qb = $this->createQueryBuilder('c'); $query = $qb->select() ->leftJoin('c.user', 'u') ->add('where', $qb->expr()->andX( $qb->expr()->orX( $qb->expr()->eq('c.status', ':inProgressStatus'), $qb->expr()->andX( $qb->expr()->eq('c.status', ':activeStatus'), $qb->expr()->isNull('c.cpanelId') ) ), $qb->expr()->eq('u.id', ':userId'), $qb->expr()->lt('c.failedInstallationAttempts', ':maxCertificateInstallationAttempts') ) ) ->setParameters([ 'inProgressStatus' => Certificate::STATUS_INPROGRESS, 'activeStatus' => Certificate::STATUS_ACTIVE, 'userId' => $user->getId(), 'maxCertificateInstallationAttempts' => $maxCertificateInstallationAttempts ]) ->getQuery() ; return $query->getResult(); } public function getExpiringCertificates(): array { $qb = $this->createQueryBuilder('c'); $twentyDaysTimestamp = (new \DateTime('+20 days'))->getTimestamp(); $thirtyDaysTimestamp = (new \DateTime('+30 days'))->getTimestamp(); $query = $qb->select() ->add('where', $qb->expr()->andX( $qb->expr()->eq('c.status', ':activeStatus'), $qb->expr()->gte('c.expires', ':twentyDaysTimestamp'), $qb->expr()->lte('c.expires', ':thirtyDaysTimestamp'), $qb->expr()->eq('c.auto_reissue_started', ':autoReissueStarted') ) ) ->setParameters([ 'activeStatus' => Certificate::STATUS_ACTIVE, 'twentyDaysTimestamp' => $twentyDaysTimestamp, 'thirtyDaysTimestamp' => $thirtyDaysTimestamp, 'autoReissueStarted' => false ]) ->getQuery(); return $query->getResult(); } /** * NC IDs of certificates that the cron should re-sync: locally still ncStatus = ACTIVE while * their expiration date has already passed, and not synced by the cron within the guard window * (a null syncedByCronAt counts as stale). Returns the IDs so the caller drives the post-sync * stamp (markSyncedByCron) from the same population. * * INELIGIBLE certificates are excluded: the status is terminal and the sync skips them * (applyNcStatusChanges never updates their ncStatus), so including them would re-trigger * the SSL list fetch on every guard window forever without any possible outcome. * * Certificates flagged as missing from the SSL list are excluded permanently for the same * reason: the fetch can never update them. The flag is cleared once the certificate reappears * in a fetched list (see SyncCertificate::applyMissingFromSslListChanges). * * @return int[] */ public function getPotentialCertificatesForSync(UserInterface $user): array { $qb = $this->createQueryBuilder('c'); $now = (new \DateTime())->getTimestamp(); $minimalSyncInterval = (new \DateTime(self::CRON_SYNC_GUARD_INTERVAL))->getTimestamp(); $rows = $qb->select('c.ncId') ->leftJoin('c.user', 'u') ->add('where', $qb->expr()->andX( $qb->expr()->eq('u.id', ':userId'), // status is nullable: a plain neq() would silently drop NULL-status rows $qb->expr()->orX( $qb->expr()->isNull('c.status'), $qb->expr()->neq('c.status', ':ineligibleStatus') ), $qb->expr()->eq('c.isMissingFromSslList', ':isMissingFromSslList'), $qb->expr()->eq('c.ncStatus', ':activeNcStatus'), $qb->expr()->lt('c.expires', ':now'), $qb->expr()->orX( $qb->expr()->isNull('c.syncedByCronAt'), $qb->expr()->lte('c.syncedByCronAt', ':minimalSyncInterval') ) ) ) ->setParameters([ 'userId' => $user->getId(), 'ineligibleStatus' => Certificate::STATUS_INELIGIBLE, 'isMissingFromSslList' => false, 'activeNcStatus' => Certificate::NCSTATUS_ACTIVE, 'now' => $now, 'minimalSyncInterval' => $minimalSyncInterval, ]) ->getQuery() ->getScalarResult(); return array_map(static fn (array $row) => (int) $row['ncId'], $rows); } /** * Stamp syncedByCronAt on the given NC IDs after a cron SSL-list fetch attempt (successful or * failed), so certificates that stay ACTIVE-but-expired (e.g. missing from the SSL list) don't * re-trigger getSslList() until the guard window elapses. * * @param int[] $ncIds */ public function markSyncedByCron(array $ncIds, int $syncedByCronAt): void { if (!$ncIds) { return; } $qb = $this->createQueryBuilder('c'); $qb->update() ->set('c.syncedByCronAt', ':syncedByCronAt') ->where($qb->expr()->in('c.ncId', ':ncIds')) ->setParameter('syncedByCronAt', $syncedByCronAt) ->setParameter('ncIds', $ncIds) ->getQuery() ->execute(); } /** * Set or clear the missing-from-SSL-list flag on the given NC IDs. Flagged certificates are * permanently excluded from getPotentialCertificatesForSync(), so a certificate the Gateway * SSL list no longer returns (e.g. transferred to another account) stops re-triggering the * list fetch. The flag is cleared when the certificate reappears in a fetched list. * * @param int[] $ncIds */ public function setMissingFromSslList(array $ncIds, bool $isMissing): void { if (!$ncIds) { return; } $qb = $this->createQueryBuilder('c'); $qb->update() ->set('c.isMissingFromSslList', ':isMissing') ->where($qb->expr()->in('c.ncId', ':ncIds')) ->setParameter('isMissing', $isMissing) ->setParameter('ncIds', $ncIds) ->getQuery() ->execute(); } public function getCertificatesMissingSubscriptionExpires(string $userName): array { $qb = $this->createQueryBuilder('c'); // select only certificates right before reissue period // if existing certificate is already passed that window - it'll be synced by AutoReissue cron $thirtyOneDaysTimestamp = (new \DateTime('+31 days'))->getTimestamp(); $thirtyTwoDaysTimestamp = (new \DateTime('+32 days'))->getTimestamp(); return $qb->select() ->leftJoin('c.user', 'u') ->add('where', $qb->expr()->andX( $qb->expr()->isNull('c.subscription_expires'), $qb->expr()->neq('c.status', ':ineligibleStatus'), $qb->expr()->gte('c.expires', ':thirtyOneDaysTimestamp'), $qb->expr()->lte('c.expires', ':thirtyTwoDaysTimestamp'), $qb->expr()->eq('u.name', ':userName') ) ) ->setParameters([ 'ineligibleStatus' => Certificate::STATUS_INELIGIBLE, 'thirtyOneDaysTimestamp' => $thirtyOneDaysTimestamp, 'thirtyTwoDaysTimestamp' => $thirtyTwoDaysTimestamp, 'userName' => $userName, ]) ->getQuery() ->getResult(); } public function removePreviousCertificate(Certificate $certificate): void { $qb = $this->createQueryBuilder('c'); $query = $qb->delete() ->add('where', $qb->expr()->andX( $qb->expr()->eq('c.host', ':host'), $qb->expr()->eq('c.user', ':userId'), $qb->expr()->neq('c.id', ':currentId') ) ) ->setParameters([ 'host' => $certificate->getHost(), 'userId' => $certificate->getUser()->getId(), 'currentId' => $certificate->getId(), ]) ->getQuery(); $query->execute(); } /** * @param int $userId * @param bool $isArrayResult * * @return array */ public function getCertificatesByUserId(int $userId): array { $qb = $this->createQueryBuilder('c'); $query = $qb->select() ->leftJoin('c.user', 'u') ->add('where', $qb->expr()->eq('u.id', ':userId') ) ->setParameters([ 'userId' => $userId ]) ->getQuery() ; return $query->getResult(); } /** * @param string $userName * * @return array */ public function getCertificatesByUserName(string $userName): array { $qb = $this->createQueryBuilder('c'); $query = $qb->select() ->leftJoin('c.user', 'u') ->add('where', $qb->expr()->eq('u.name', ':userName') ) ->addOrderBy('c.ncId', 'ASC') ->setParameters([ 'userName' => $userName ]) ->getQuery() ; return $query->getArrayResult(); } /** * @param int $userId * @param string $userNcLogin * * @return array */ public function getCertificatesForLocalDbUpdate(int $userId, string $userNcLogin): array { $qb = $this->createQueryBuilder('c'); $query = $qb->select() ->leftJoin('c.user', 'u') ->add('where', $qb->expr()->andX( $qb->expr()->eq('u.id', ':userId'), $qb->expr()->eq('u.ncLogin', ':userNcLogin') ) ) ->setParameters([ 'userId' => $userId, 'userNcLogin' => $userNcLogin ]) ->getQuery() ; return $query->getArrayResult(); } /** * @param int $id * @param int $userId * * @return void */ public function deleteById(int $id, int $userId): void { $qb = $this->createQueryBuilder('c'); $query = $qb->delete() ->add('where', $qb->expr()->andX( $qb->expr()->eq('c.id', ':id'), $qb->expr()->eq('c.user', ':userId') ) ) ->setParameters([ 'id' => $id, 'userId' => $userId, ]) ->getQuery(); $query->execute(); } public function updateSubscriptionExpiresById(int $certificateId, int $subscriptionExpires): void { $qb = $this->createQueryBuilder('c'); $qb->update() ->set('c.subscription_expires', ':subscriptionExpires') ->where('c.id = :id') ->setParameter('subscriptionExpires', $subscriptionExpires) ->setParameter('id', $certificateId) ->getQuery() ->execute(); } public function updateToggle(int $certificateId, bool $status): void { if ($certificateId === 0) { throw new \InvalidArgumentException('Certificate Id is empty'); } $qb = $this->createQueryBuilder('c'); $qb->update() ->set('c.autoRedirect', ':status') ->where('c.ncId = :certificateId') ->setParameter('status', $status) ->setParameter('certificateId', $certificateId) ->getQuery() ->execute(); } }
Save