#!/usr/bin/php id); define("INTERNAL_USER_USERNAME", $me->username); $ignore_preorders = []; $campaign_prem_sued = 6; $createOrderEp = RIMO_API_JSON_URL."/createOrder"; $ctx_opts = [ 'http' => [ 'method' => 'POST', 'header' => 'accept: application/json' ] ]; $missing_units = []; $missing_extrefs = []; foreach(PreorderModel::searchActive(["preordercampaign_id" => $campaign_prem_sued]) as $preorder) { if(in_array($preorder->id, $ignore_preorders)) continue; if($preorder->workorder_export_date) continue; if(!$preorder->adb_wohneinheit_id) { //echo "Keine Wohneinheit in Preorder (".$preorder->id.") ".$preorder->ucode." ".$preorder->oaid."\n"; $missing_units[] = $preorder; continue; } $wohneinheit = new ADBWohneinheit($preorder->adb_wohneinheit_id); if(!$wohneinheit->id) { echo "Wohneinheit nicht gefunden (Preorder ".$preorder->id." ".$preorder->ucode." ".$preorder->oaid.")\n"; continue; } if(!$wohneinheit->extref) { $missing_extrefs[] = $preorder; continue; } if(!$preorder->oaid) { if(!$wohneinheit->oaid) { $wohneinheit->oaid = $wohneinheit->getNewOAID(); $wohneinheit->save(); } $preorder->oaid = $wohneinheit->oaid; $preorder->save(); } $params['apiKey'] = RIMO_API_JSON_APIKEY; $params["homeId"] = $wohneinheit->extref; $params["firstName"] = trim($preorder->firstname); $params["lastName"] = trim($preorder->lastname); $params["company"] = trim($preorder->company); $params["phone"] = trim($preorder->phone); $params["email"] = trim($preorder->email); $params["orderId"] = $preorder->ucode; $params["openAccessId"] = $preorder->oaid; $qs = http_build_query($params); //echo $qs."\n"; $post_url = $createOrderEp."?".$qs; $ctx = stream_context_create($ctx_opts); $response = file_get_contents($post_url, false, $ctx); if($response === false) { echo "Fehler beim Exportieren der Workorder für Preorder ".$preorder->id." ".$preorder->ucode." ".$preorder->oaid."\n"; continue; } $preorder->workorder_export_date = date('U'); $preorder->workorder_export_data = $response; $preorder->save(); //var_dump($preorder, $response); //exit; } echo "\n"; foreach($missing_units as $preorder) { echo "Keine Wohneinheit in Preorder ".$preorder->id." ".$preorder->ucode." ".$preorder->oaid."\n"; } echo "\n"; foreach($missing_extrefs as $preorder) { echo "Keine Extref für Wohneinheit: Preorder ".$preorder->id." ".$preorder->ucode." ".$preorder->oaid."\n"; }