doublesecretagency / craft-adwizard

Ad Wizard plugin for Craft CMS
Other
7 stars 8 forks source link

PostgreSQL Support (Undefined function: 7 ERROR: operator does not exist: boolean = integer) #24

Closed pgrzyb closed 3 years ago

pgrzyb commented 3 years ago

Hi there! I am trying to use your plugin on one of our client projects, but sadly it doesn't seem to run on PostgreSQL. All of the template tags end in the same error messages:

SQLSTATE[42883]: Undefined function: 7 ERROR: operator does not exist: boolean = integer
LINE 4: WHERE ("ads"."id"=$1) AND ("elements"."enabled" = 1) AND ("a...
^
HINT: No operator matches the given name and argument types. You might need to add explicit type casts.
The SQL being executed was: SELECT "ads"."id"
FROM "adwizard_ads" "ads"
INNER JOIN "elements" "elements" ON "ads"."id" = "elements"."id"
WHERE ("ads"."id"=31829) AND ("elements"."enabled" = 1) AND ("ads"."assetId" IS NOT NULL) AND (("ads"."startDate" <= '2021-01-23 20:03:52') OR ("ads"."startDate" IS NULL)) AND (("ads"."endDate" >= '2021-01-23 20:03:52') OR ("ads"."endDate" IS NULL)) AND (("ads"."totalViews" < "ads"."maxViews") OR ("ads"."maxViews" = 0) OR ("ads"."maxViews" IS NULL))
ORDER BY RAND()
LIMIT 1

I'm nowhere near being a PHP expert, and fiddling with source files is not something I would normally do, but this project strongly relies on an ad solution that AdWizard provides, and it seems like you guys monopolized this area of the Craft plugin store :P I gave it a shot and here's what I found:

Changing the query in getValidAdId() in /src/services/Ads.php a bit does the trick, but it's not a valid long term solution, since we are running composer install during deployment overwriting any manual changes I make to the plugin :(

The changes I am referring to are:

line 219: ->andWhere('[[elements.enabled]] = 1') => ->andWhere('[[elements.enabled]] = true')

line 224: ->orderBy('RAND()') => ->orderBy('random()')

Any chance this could get fixed and released in the foreseeable future?

pgrzyb commented 3 years ago

Something like this maybe? -> #25

lindseydiloreto commented 3 years ago

This is live in v3.1.2. Thanks for the PR! 🍺