Added preorderTrigger / added cif api docs

This commit is contained in:
Frank Schubert
2024-02-26 23:13:30 +01:00
parent 26d022441d
commit 2af51a2f57
7 changed files with 425 additions and 186 deletions

View File

@@ -48,6 +48,8 @@ class Preorder extends mfBaseModel {
$this->save();
}
// run triggers based on new status
$this->runStatusTrigger();
// Cascade status changes down to adb_hausnummer and adb_wohneinheit
$this->cascadeStatus();
// Cascade status changes down all active preorders with the same hausnummer
@@ -56,6 +58,59 @@ class Preorder extends mfBaseModel {
$this->in_after_save--;
}
public function runStatusTrigger() {
if(!$this->id) return true;
if($this->status_id == $this->_old_data->status_id) return true;
$this->log->debug(__METHOD__." running");
$new_status = $this->getProperty("status");
$old_status = new Preorderstatus($this->_old_data->status_id);
if(!$new_status->id || !$old_status->id) return true;
$this->log->debug(__METHOD__." status changed from '".($old_status ? $old_status->code : "")."' to '".$new_status->code."'");
if($new_status->code <= $old_status->code) return true;
if(!defined("TT_PREORDER_STATUS_MATRIX") || !TT_PREORDER_STATUS_MATRIX) {
$this->log->error("config TT_PREORDER_STATUS_MATRIX not defined!");
}
// run every trigger bnetween old and new status code
foreach(TT_PREORDER_STATUS_MATRIX as $intermediate_code => $status) {
if($intermediate_code <= $old_status->code) continue;
if($intermediate_code > $new_status->code) continue;
$code = $intermediate_code;
// find trigger for new status code
$classname = "Preorder_Statustrigger_$code";
$filepath = __DIR__."/statustrigger/$code.php";
$this->log->debug(__METHOD__.": Looking for $classname in $filepath");
if(!file_exists($filepath)) {
$this->log->debug(__METHOD__.": $filepath not found");
continue;
}
require_once $filepath;
if(!class_exists($classname)) {
$this->log->debug(__METHOD__.": $classname not found");
continue;
}
$trigger = new $classname($this, $new_status);
$trigger->run();
}
return true;
}
/*
* Cascade status changes down to adb_hausnummer and adb_wohneinheit
*/
@@ -400,6 +455,7 @@ class Preorder extends mfBaseModel {
$hausnummer = $this->getProperty("adb_hausnummer");
$wohneinheit = $this->getProperty("adb_wohneinheit");
$campaign = $this->getProperty("campaign");
$a = [];
$a["ciftoken"] = $this->ciftoken;

View File

@@ -1016,6 +1016,9 @@ class PreorderController extends mfBaseController {
"text" => $affected_preorder->status->name,
"bcode" => $affected_preorder->adb_hausnummer->status->code,
"btext" => $affected_preorder->adb_hausnummer->status->name,
"ciftoken" => $affected_preorder->ciftoken,
"cifurl" => $affected_preorder->cifurl,
"cifcableurl" => $affected_preorder->cifcableurl,
];
if($preorder->adb_wohneinheit_id) {
$up["ucode"] = $affected_preorder->adb_wohneinheit->status->code;

View File

@@ -0,0 +1,46 @@
<?php
class Preorder_Statustrigger_145 {
private $log;
private $preorder;
private $new_status;
public function __construct(Preorder $preorder, Preorderstatus $new_status) {
$this->log = mfLoghandler::singleton();
$this->preorder = $preorder;
$this->new_status = $new_status;
}
public function run() {
$this->log->debug(__METHOD__.": running trigger");
$changes = false;
if(!$this->preorder->ciftoken) {
$this->preorder->ciftoken = $this->preorder->createCiftoken();
$changes = true;
}
/*if(!$this->preorder->ciftoken) {
$this->log->warning("Error creating ciftoken for preorder ".$this->preorder->id);
return true;
}*/
if(!$this->preorder->cifurl) {
$this->preorder->cifurl = $this->preorder->generateCifUrl();
$changes = true;
}
if(!$this->preorder->cifcableurl) {
$this->preorder->cifcableurl = $this->preorder->generateCifCableUrl();
$changes = true;
}
if($changes) {
$this->preorder->save();
}
return true;
}
}

View File

@@ -6,6 +6,7 @@ class UserToken extends mfBaseController
public static function checkToken()
{
if (isset($_COOKIE[MFAPPNAME . '_remembertoken'])) {
$refresh = false;
$cookie = explode(':', $_COOKIE[MFAPPNAME . '_remembertoken']);
if (count($cookie) === 2) {
$db = new FronkDB();