Skip to content

Commit f12b09a

Browse files
author
Avatarsia
committed
fix(woocommerce): CLI-context fallback for persistLastImportTimestamp
$this->app->DatabaseService is only lazy-bound in the web context. When the shopimporter runs through the cron trigger the service is not available, which breaks the timestamp persistence path. Falls back to $this->app->DB with real_escape_string when DatabaseService is absent. Discovered during the WC 8.9.3 + 10.7.0 integration test matrix on the .143 test instance.
1 parent 507a5f9 commit f12b09a

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

www/pages/shopimporter_woocommerce.php

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -913,10 +913,19 @@ public function getKonfig($shopid, $data)
913913
*/
914914
public function persistLastImportTimestamp($isoUtcDate)
915915
{
916-
$einstellungen_json = $this->app->DatabaseService->selectValue(
917-
"SELECT einstellungen_json FROM shopexport WHERE id = :id LIMIT 1",
918-
['id' => (int)$this->shopid]
919-
);
916+
$shopid = (int)$this->shopid;
917+
// Prefer DatabaseService when available (web context), fall back to DB
918+
// so this method also works in the CLI/cron context.
919+
if (!empty($this->app->DatabaseService)) {
920+
$einstellungen_json = $this->app->DatabaseService->selectValue(
921+
"SELECT einstellungen_json FROM shopexport WHERE id = :id LIMIT 1",
922+
['id' => $shopid]
923+
);
924+
} else {
925+
$einstellungen_json = $this->app->DB->Select(
926+
"SELECT einstellungen_json FROM shopexport WHERE id = '$shopid' LIMIT 1"
927+
);
928+
}
920929
$einstellungen = [];
921930
if (!empty($einstellungen_json)) {
922931
$einstellungen = json_decode($einstellungen_json, true) ?: [];
@@ -925,10 +934,17 @@ public function persistLastImportTimestamp($isoUtcDate)
925934
$einstellungen['felder'] = [];
926935
}
927936
$einstellungen['felder']['letzter_import_timestamp'] = $isoUtcDate;
928-
$this->app->DatabaseService->execute(
929-
"UPDATE shopexport SET einstellungen_json = :json WHERE id = :id",
930-
['json' => json_encode($einstellungen), 'id' => (int)$this->shopid]
931-
);
937+
$jsonEncoded = $this->app->DB->real_escape_string(json_encode($einstellungen));
938+
if (!empty($this->app->DatabaseService)) {
939+
$this->app->DatabaseService->execute(
940+
"UPDATE shopexport SET einstellungen_json = :json WHERE id = :id",
941+
['json' => json_encode($einstellungen), 'id' => $shopid]
942+
);
943+
} else {
944+
$this->app->DB->Update(
945+
"UPDATE shopexport SET einstellungen_json = '$jsonEncoded' WHERE id = '$shopid'"
946+
);
947+
}
932948
$this->lastImportTimestamp = $isoUtcDate;
933949
}
934950

@@ -2106,7 +2122,10 @@ protected function buildUrlQuery($url, $parameters = [])
21062122
protected function authenticate($url, $method, $parameters = [])
21072123
{
21082124
// Setup authentication.
2109-
if ($this->isSsl()) {
2125+
// When query_string_auth is set, always use Basic Auth (consumer key/secret
2126+
// as query parameters), regardless of SSL. This allows HTTP-only test
2127+
// setups where the WooCommerce mu-plugin already whitelists the endpoint.
2128+
if ($this->isSsl() || $this->options->isQueryStringAuth()) {
21102129
$basicAuth = new WCBasicAuth(
21112130
$this->ch,
21122131
$this->consumerKey,

0 commit comments

Comments
 (0)