Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL Fehler bei Newsletter Versand #4

Closed
reluem opened this issue Mar 12, 2017 · 20 comments
Closed

SQL Fehler bei Newsletter Versand #4

reluem opened this issue Mar 12, 2017 · 20 comments
Labels

Comments

@reluem
Copy link

reluem commented Mar 12, 2017

Beim Versuch, die Nachrichten an bestätigte Abonnenten zu versenden, kommt leider folgender Fehler:

PHP Fatal error: Uncaught exception 'Exception' with message 'Query error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1 (SELECT id, name AS value FROM tl_member_group WHERE id IN ())' thrown in /is/htdocs/xx/www/xx/system/modules/core/library/Contao/Database/Statement.php on line 295

Andere Newsletter ohne News funktionieren weiterhin.
Contao 3.5.24 mit PHP 7.0.16-he.0

@qzminski
Copy link
Member

@terminal42/pilots I had exactly the same issue in my extension. There are basically two problems with formatting all available model data using Haste\Util\Format:

  1. The options_callback field setting may require the DataContainer object which is often not available.
  2. If the foriegnKey field settings is present but no value was given it results in an error presented above. Maybe we should provide the 0 value instead.

To workaround those problem I have did some dirty tricks, see here: codefog/contao-events_subscriptions@e173111

Maybe we should fix it in the Haste though?

@Xendiadyon
Copy link

I guess you correctly identified the problem. However, I don't understand your solution.

So I guess that Haste should indeed be fixed :(

@qzminski
Copy link
Member

@Xendiadyon likely yes but I am waiting for other contributors to provide some feedback.

@netzarbeiter
Copy link
Sponsor Member

I came across the same problem with the query error, how can I help to get things done?

@Xendiadyon
Copy link

Dirty Hack, von dem ich nicht weiß, ob der jetzt zuverlässig funktioniert oder ob er weitere Probleme verursacht (Umsetzung nur auf eigene Gefahr)

Es gibt Probleme mit dem übergebenen Objekt in der Erweiterung "haste" (Grundlage für quasi alles).

Der Workaround in /www/htdocs/system/modules/haste/library/Haste/Util/Format.php: wenn "varValue" leer ist, setze "0" in der MySQL-Abfrage (Z.152-155).
Wenn das "objDc" nicht übergeben ist (Z.140,145), führe die Abfragen nicht aus.

image

@Toflar
Copy link
Member

Toflar commented Mar 20, 2017

The options_callback field setting may require the DataContainer object which is often not available.

Which is not an issue of haste, right?

If the foriegnKey field settings is present but no value was given it results in an error presented above. Maybe we should provide the 0 value instead.

Yeah, this issue should be fixable by turning this

$objOptions = \Database::getInstance()->query("SELECT id, " . $chunks[1] . " AS value FROM " . $chunks[0] . " WHERE id IN (" . implode(',', array_map('intval', (array) $varValue)) . ")");

into this:

$ids = 0 === count((array) $varValue) ? [0] : (array) $varValue;
$objOptions = \Database::getInstance()->query("SELECT id, " . $chunks[1] . " AS value FROM " . $chunks[0] . " WHERE id IN (" . implode(',', array_map('intval', $ids)) . ")");

@qzminski
Copy link
Member

Which is not an issue of haste, right?

Not the Haste issue but since we are providing this utility we should handle that case I think. In most of the cases you need just a DataContainer mockup which contains basic data such as id, table name and the active record data. That we can do imo by providing an extra method to mockup this object and then developer can decide whether to use it or not.

@Toflar
Copy link
Member

Toflar commented Mar 20, 2017

Imho the options_callback is a whole different story and it's not related to haste at all. You can pass it if you like. It's not haste's responsibility.
The original issue should be fixed with my code, did anyone test this?

@Xendiadyon
Copy link

but haste should not throw an error if the options_callback is not passed?

@Toflar
Copy link
Member

Toflar commented Mar 20, 2017

Haste doesn't throw an error? The initial error in this issue should be fixed with my piece of code, please test this.

@netzarbeiter
Copy link
Sponsor Member

Used this:

$ids = 0 === count((array) $varValue) : [0] : (array) $varValue;
$objOptions = \Database::getInstance()->query("SELECT id, " . $chunks[1] . " AS value FROM " . $chunks[0] . " WHERE id IN (" . implode(',', array_map('intval', $ids)) . ")");

Error:
app.CRITICAL: An exception occurred. {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Parse error: syntax error, unexpected ':' at /home/username/public_html/domain.ch/vendor/codefog/contao-haste/library/Haste/Util/Format.php:150)"} []

Used this:

$ids = 0 === count((array) $varValue) ? [0] : (array) $varValue;
$objOptions = \Database::getInstance()->query("SELECT id, " . $chunks[1] . " AS value FROM " . $chunks[0] . " WHERE id IN (" . implode(',', array_map('intval', $ids)) . ")");

Error:
app.CRITICAL: An exception occurred. {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Type error: Argument 1 passed to tl_news_archive_newsletter::getNotificationChoices() must be an instance of Contao\\DataContainer, null given, called in /home/user/public_html/domain.ch/vendor/codefog/contao-haste/library/Haste/Util/Format.php on line 142 at /home/user/public_html/domain.ch/vendor/terminal42/contao-news_newsletter/dca/tl_news_archive.php:65)"} []

@qzminski
Copy link
Member

Try this:

$ids = $varValue ? (array) $varValue : [0];

@netzarbeiter
Copy link
Sponsor Member

Used this:

$ids = $varValue ? (array) $varValue : [0];
$objOptions = \Database::getInstance()->query("SELECT id, " . $chunks[1] . " AS value FROM " . $chunks[0] . " WHERE id IN (" . implode(',', array_map('intval', $ids)) . ")");

Same error:
app.CRITICAL: An exception occurred. {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Type error: Argument 1 passed to tl_news_archive_newsletter::getNotificationChoices() must be an instance of Contao\\DataContainer, null given, called in /home/user/public_html/domain.ch/vendor/codefog/contao-haste/library/Haste/Util/Format.php on line 142 at /home/user/public_html/domain.ch/vendor/terminal42/contao-news_newsletter/dca/tl_news_archive.php:65)"} []

@qzminski
Copy link
Member

Ah sorry, did not look at the error message 😄 that line is irrelevant, the error you are getting refers to the DataContainer problem.

@Toflar
Copy link
Member

Toflar commented Mar 20, 2017

So @qzminski would you provide a dc wrapper or what's your idea?

@qzminski
Copy link
Member

I opt for a workaround from my other project:

codefog/contao-events_subscriptions@e173111

@Toflar
Copy link
Member

Toflar commented Mar 20, 2017

Well, I guess it would work for most cases but at the same time it's also dangerous somehow :)

@qzminski
Copy link
Member

It is indeed, yet I can't think of other solution really. This mock would be passed only and only to the options_callback anyway and I highly doubt anyone would call some method from it.

@qzminski
Copy link
Member

For further discussion and hotfix please see codefog/contao-haste#101.

I will let this task open however to bump the necessary dependencies in the composer.json file later on.

@reluem
Copy link
Author

reluem commented Apr 2, 2017

seems to be working now! Issue can be closed.

@qzminski qzminski closed this as completed Apr 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants