ENHANCEMENT: Deleting with doctrine
This commit is contained in:
parent
2fa127205c
commit
fee48b7a99
|
@ -57,7 +57,7 @@ class Job
|
||||||
/**
|
/**
|
||||||
* @var Collection
|
* @var Collection
|
||||||
*/
|
*/
|
||||||
#[ORM\OneToMany(targetEntity: "App\Entity\Run", mappedBy: "job")]
|
#[ORM\OneToMany(targetEntity: "App\Entity\Run", mappedBy: "job", cascade: ["remove"])]
|
||||||
private Collection $runs;
|
private Collection $runs;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
|
|
|
@ -9,7 +9,6 @@ use App\Entity\Run;
|
||||||
use App\Service\Secret;
|
use App\Service\Secret;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use Doctrine\ORM\EntityRepository;
|
use Doctrine\ORM\EntityRepository;
|
||||||
use Doctrine\ORM\Query;
|
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
use GuzzleHttp\Exception\GuzzleException;
|
use GuzzleHttp\Exception\GuzzleException;
|
||||||
use phpseclib3\Crypt\PublicKeyLoader;
|
use phpseclib3\Crypt\PublicKeyLoader;
|
||||||
|
@ -673,8 +672,11 @@ class JobRepository extends EntityRepository
|
||||||
|
|
||||||
public function deleteJob(int $id)
|
public function deleteJob(int $id)
|
||||||
{
|
{
|
||||||
$this->getEntityManager()->getConnection()->prepare("DELETE FROM job WHERE id = :id")->executeStatement([':id' => $id]);
|
$em = $this->getEntityManager();
|
||||||
$this->getEntityManager()->getConnection()->prepare("DELETE FROM run WHERE job_id = :id")->executeStatement([':id' => $id]);
|
|
||||||
|
$job = $this->find($id);
|
||||||
|
$em->remove($job);
|
||||||
|
$em->flush();
|
||||||
|
|
||||||
return ['success' => true, 'message' => 'Cronjob succesfully deleted'];
|
return ['success' => true, 'message' => 'Cronjob succesfully deleted'];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue