| 1 |
<?php |
| 2 |
|
| 3 |
namespace IvyForms\Services\GoogleSheets\Hooks; |
| 4 |
|
| 5 |
use IvyForms\Repository\GoogleSheets\GoogleSheetsRepositoryInterface; |
| 6 |
|
| 7 |
/** |
| 8 |
* Cleans up Google Sheets integrations when a form is deleted. |
| 9 |
*/ |
| 10 |
class GoogleSheetsFormHooks |
| 11 |
{ |
| 12 |
private GoogleSheetsRepositoryInterface $repository; |
| 13 |
|
| 14 |
public function __construct(GoogleSheetsRepositoryInterface $repository) |
| 15 |
{ |
| 16 |
$this->repository = $repository; |
| 17 |
} |
| 18 |
|
| 19 |
public function register(): void |
| 20 |
{ |
| 21 |
add_action('ivyforms/form/before_delete', [$this, 'onFormDelete']); |
| 22 |
} |
| 23 |
|
| 24 |
public function onFormDelete(int $formId): void |
| 25 |
{ |
| 26 |
if ($formId <= 0) { |
| 27 |
return; |
| 28 |
} |
| 29 |
|
| 30 |
$this->repository->deleteByFormId($formId); |
| 31 |
} |
| 32 |
} |
| 33 |
|