# Eigener Cronjob als Plugin wird nicht ausgeführt

**URL:** <https://forum.shopware.com/t/eigener-cronjob-als-plugin-wird-nicht-ausgefuhrt/26371>\
**Category:** Shopware 3.5\
**Tags:** programming\
**Created:** [20. April 2015 um 17:44 UTC](https://forum.shopware.com/t/eigener-cronjob-als-plugin-wird-nicht-ausgefuhrt/26371 "2015-04-20T17:44:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![eierund](https://avatars.discourse-cdn.com/v4/letter/e/e8c25b/32.png) [@eierund](https://forum.shopware.com/u/eierund)\
**Post date:** [20. April 2015 um 17:44 UTC](https://forum.shopware.com/t/eigener-cronjob-als-plugin-wird-nicht-ausgefuhrt/26371/1 "2015-04-20T17:44:07Z")

</div>

Hallo, ich habe ein Plugin erstellt, welches einen Cronjob installiert, der wiederum eine Datenbankabfrage laufen lassen soll. Leider funktioniert irgendwas nicht. Der Cron steht derzeit auf 2 Minuten, wenn ich Ihn manuell ausführe über /backend/cron, dann steht dort zwar “Processing SetVariantAktive” aber es passiert nichts. Hier der Code ` private function registerEvents() { $this-\>subscribeEvent( 'Enlight\_Controller\_Action\_PostDispatch\_Frontend\_Index', 'onPostDispatchFrontend' ); } private function registerCronJobs() { $this-\>subscribeEvent( 'Shopware\_CronJob\_SetActive', 'onRunSetActiveCronJob' ); $this-\>createCronJob( 'SetActive', 'SetActiveCron', 900, true ); } public function onRunSetActiveCronJob(\Shopware\_Components\_Cron\_CronJob $job) { //first we have to get the current active slogan $sql= "UPDATE `db-sandbox`.`s_articles_details` SET `active` = '1' WHERE `s_articles_details`.`instock` \> 10"; Shopware()-\>Db()-\>fetchAll($sql); }` Kann mir da jemand helfen, bin noch neue in dieser Programmierung 🙂

---

<div class="post-metadata">

**Author:** ![Thomas](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/thomas/32/8167_2.png) [@Thomas](https://forum.shopware.com/u/Thomas)\
**Post date:** [20. April 2015 um 17:49 UTC](https://forum.shopware.com/t/eigener-cronjob-als-plugin-wird-nicht-ausgefuhrt/26371/2 "2015-04-20T17:49:25Z")

</div>

Versuch es einmal so: ` &nbsp;&nbsp;&nbsp; private function registerCronJobs() &nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; $this-\>subscribeEvent( &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'Shopware\_CronJob\_SetActive', &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'onRunSetActiveCronJob' &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; ); &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; $this-\>createCronJob( &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'SetActive', &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'SetActive', &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 900, &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; true &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; ); &nbsp;&nbsp;&nbsp; } ` Gruß

---

<div class="post-metadata">

**Author:** ![eierund](https://avatars.discourse-cdn.com/v4/letter/e/e8c25b/32.png) [@eierund](https://forum.shopware.com/u/eierund)\
**Post date:** [20. April 2015 um 18:10 UTC](https://forum.shopware.com/t/eigener-cronjob-als-plugin-wird-nicht-ausgefuhrt/26371/3 "2015-04-20T18:10:32Z")

</div>

Hallo, super, das funktioniert schonmal. Der SQL Befehl wird ausgeführt, dann gibt es allerdings einen Fehler, der den Cronjob auch deaktiviert: `array ( 'error' =\> 'SQLSTATE[HY000]: General error', )` Was ist da wieder los? Finde leider bei Google keine passenden Hilfsmethoden.

---

<div class="post-metadata">

**Author:** ![ottscho](https://avatars.discourse-cdn.com/v4/letter/o/7ba0ec/32.png) [@ottscho](https://forum.shopware.com/u/ottscho)\
**Post date:** [20. April 2015 um 18:36 UTC](https://forum.shopware.com/t/eigener-cronjob-als-plugin-wird-nicht-ausgefuhrt/26371/4 "2015-04-20T18:36:46Z")

</div>

Du musst Return true; zurück liefern.

---

<div class="post-metadata">

**Author:** ![Thomas](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/thomas/32/8167_2.png) [@Thomas](https://forum.shopware.com/u/Thomas)\
**Post date:** [20. April 2015 um 20:56 UTC](https://forum.shopware.com/t/eigener-cronjob-als-plugin-wird-nicht-ausgefuhrt/26371/5 "2015-04-20T20:56:08Z")

</div>

und anstatt fetchAll() query() verwenden. Dann sollte es funktionieren 🙂 Gruß

---

<div class="post-metadata">

**Author:** ![eierund](https://avatars.discourse-cdn.com/v4/letter/e/e8c25b/32.png) [@eierund](https://forum.shopware.com/u/eierund)\
**Post date:** [21. April 2015 um 10:51 UTC](https://forum.shopware.com/t/eigener-cronjob-als-plugin-wird-nicht-ausgefuhrt/26371/6 "2015-04-21T10:51:34Z")

</div>

Ah, ich verstehe. Super, das funktioniert! Vielen Dank!
