solspace / craft-calendar

Calendar for Craft: The most reliable and powerful event management plugin for Craft.
http://docs.solspace.com/craft/calendar/v5
Other
15 stars 15 forks source link

Saving new calendar event causes error #149

Closed mudechs closed 2 years ago

mudechs commented 2 years ago

Hi there

If i try to add a new calendar event i get a error. Resaving of existing entries works as expected. At this time it is a show-stopper for my client.

Craft Version: 3.7.47.1 Solspace Calendar Version: 3.3.13.1 Database: MySQL 5.5.5 PHP Version: 7.4.30

The following error occurs:

Argument 1 passed to Solspace\Calendar\Services\EventsService::getEventById() must be of the type int, null given, called in /home/httpd/vhosts/tanzhaus-zuerich.ch/core/vendor/solspace/craft3-calendar/packages/plugin/src/Services/EventsService.php on line 498

And here the stack trace:

`1. in /home/httpd/vhosts/tanzhaus-zuerich.ch/core/vendor/solspace/craft3-calendar/packages/plugin/src/Services/EventsService.phpat line 38 29303132333435363738394041424344454647 const EVENT_AFTER_DELETE = 'afterDelete';

/**
 * Returns an event by its ID.
 *
 * @param int $siteId
 *
 * @return null|ElementInterface|Event
 */
public function getEventById(int $eventId, int $siteId = null, bool $includeDisabled = false)
{
    $query = Event::find()
        ->setAllowedCalendarsOnly(false)
        ->status($includeDisabled ? null : Element::STATUS_ENABLED)
        ->id($eventId)
    ;

    if (null !== $siteId) {
        $query->siteId($siteId);
  1. in /home/httpd/vhosts/tanzhaus-zuerich.ch/core/vendor/solspace/craft3-calendar/packages/plugin/src/Services/EventsService.php at line 498– Solspace\Calendar\Services\EventsService::getEventById(null, 2) 492493494495496497498499500501502503504 // So if $event siteId is 1 and $event supports site ids in 1, 2 and 3, we want to grab 2 and 3... $supportedSites = ArrayHelper::index(ElementHelper::supportedSitesForElement($event), 'siteId'); $otherSiteIds = ArrayHelper::withoutValue(array_keys($supportedSites), $event->siteId);

        if (! empty($otherSiteIds)) {
            foreach ($otherSiteIds as $otherSiteId) {
                $otherSiteEvent = $this->getEventById($event->id, $otherSiteId);
    
                if ($otherSiteEvent) {
                    $otherSiteEvents[] = $otherSiteEvent;
                }
            }
        }
  2. in /home/httpd/vhosts/tanzhaus-zuerich.ch/core/vendor/solspace/craft3-calendar/packages/plugin/src/Services/EventsService.php at line 210– Solspace\Calendar\Services\EventsService::_respectNonTranslatableFields(Solspace\Calendar\Elements\Event, false) 204205206207208209210211212213214215216 if ($saveEvent->isValid) { $transaction = \Craft::$app->db->beginTransaction();

        try {
            $isSaved = \Craft::$app->elements->saveElement($event, $validateContent, $isNewEvent);
            $isSaved = $this->_respectNonTranslatableFields($event, $isSaved);
            if ($isSaved) {
                $this->reindexSearchForAllSites($event);
    
                if (null !== $transaction) {
                    $transaction->commit();
                }
  3. in /home/httpd/vhosts/tanzhaus-zuerich.ch/core/vendor/solspace/craft3-calendar/packages/plugin/src/Controllers/EventsController.php at line 248– Solspace\Calendar\Services\EventsService::saveEvent(Solspace\Calendar\Elements\Event) 242243244245246247248249250251252253254 // Save the entry (finally!) if ($event->enabled && $event->enabledForSite) { $event->setScenario(Element::SCENARIO_LIVE); }

    if ($this->getEventsService()->saveEvent($event)) {
        $event->siteId = $siteId;
    
        // Return JSON response if the request is an AJAX request
        if (\Craft::$app->request->isAjax) {
            return $this->asJson(['success' => true]);
        }
  4. Solspace\Calendar\Controllers\EventsController::actionSaveEvent()

  5. in /home/httpd/vhosts/tanzhaus-zuerich.ch/core/vendor/yiisoft/yii2/base/InlineAction.php at line 57– call_user_func_array([Solspace\Calendar\Controllers\EventsController, 'actionSaveEvent'], [])

  6. in /home/httpd/vhosts/tanzhaus-zuerich.ch/core/vendor/yiisoft/yii2/base/Controller.php at line 178– [yii\base\InlineAction::runWithParams](http://www.yiiframework.com/doc-2.0/yii-base-inlineaction.html#runWithParams()-detail)(['p' => 'tyU4x3PX8x/calendar/events/new/t...'])

  7. in /home/httpd/vhosts/tanzhaus-zuerich.ch/core/vendor/yiisoft/yii2/base/Module.php at line 552– [yii\base\Controller::runAction](http://www.yiiframework.com/doc-2.0/yii-base-controller.html#runAction()-detail)('save-event', ['p' => 'tyU4x3PX8x/calendar/events/new/t...'])

  8. in /home/httpd/vhosts/tanzhaus-zuerich.ch/core/vendor/craftcms/cms/src/web/Application.php at line 293– [yii\base\Module::runAction](http://www.yiiframework.com/doc-2.0/yii-base-module.html#runAction()-detail)('calendar/events/save-event', ['p' => 'tyU4x3PX8x/calendar/events/new/t...']) 287288289290291292293294295296297298299 * @param string $route

    • @param array $params
    • @return Response|null The result of the action, normalized into a Response object */ public function runAction($route, $params = []) { $result = parent::runAction($route, $params);

      if ($result !== null) { if ($result instanceof Response) { return $result; }

  9. in /home/httpd/vhosts/tanzhaus-zuerich.ch/core/vendor/craftcms/cms/src/web/Application.php at line 602– craft\web\Application::runAction('calendar/events/save-event', ['p' => 'tyU4x3PX8x/calendar/events/new/t...']) 596597598599600601602603604605606607608 if ($request->getIsActionRequest()) { $route = implode('/', $request->getActionSegments());

        try {
            Craft::debug("Route requested: '$route'", __METHOD__);
            $this->requestedRoute = $route;
            return $this->runAction($route, $_GET);
        } catch (\Throwable $e) {
            $this->_unregisterDebugModule();
            if ($e instanceof InvalidRouteException) {
                throw new NotFoundHttpException(Craft::t('yii', 'Page not found.'), $e->getCode(), $e);
            }
            throw $e;
  10. in /home/httpd/vhosts/tanzhaus-zuerich.ch/core/vendor/craftcms/cms/src/web/Application.php at line 272– craft\web\Application::_processActionRequest(craft\web\Request) 266267268269270271272273274275276277278 throw new ForbiddenHttpException(); } } }

    // If this is an action request, call the controller
    if (($response = $this->_processActionRequest($request)) !== null) {
        return $response;
    }
    
    // If we're still here, finally let Yii do it's thing.
    try {
        return parent::handleRequest($request);
  11. in /home/httpd/vhosts/tanzhaus-zuerich.ch/core/vendor/yiisoft/yii2/base/Application.php at line 384– craft\web\Application::handleRequest(craft\web\Request)

  12. in /home/httpd/vhosts/tanzhaus-zuerich.ch/httpdocs/index.php at line 21– [yii\base\Application::run](http://www.yiiframework.com/doc-2.0/yii-base-application.html#run()-detail)() 15161718192021 (new Dotenv\Dotenv(CRAFT_BASE_PATH))->load(); }

// Load and run Craft define('CRAFT_ENVIRONMENT', getenv('ENVIRONMENT') ?: 'production'); $app = require CRAFT_VENDOR_PATH.'/craftcms/cms/bootstrap/web.php'; $app->run(); $_GET = [ 'p' => 'tyU4x3PX8x/calendar/events/new/trainingWorkshops/tanzhausZuerichDe', ];

$_POST = [ 'CRAFT_CSRF_TOKEN' => 'K1nzi3ieYYHqZcj98KZtswLIvZCCEjZUhR7O--jqwcfIa9TyT3NZrRf0v7kbVgToDFjukuTBJ7K3A8EfHJvylIKGAOf0tULLR_4yQIbChQ2bzCuUXKX57tC1MOlKenTZHVeePn0jqmbj-2vbgx6dPDI9geGk62ulrY30452cQjVYZlwxgmpcPtzy28IN20tCE2AEQm2fugHcCPikLbC1v_U93Ur6_KWyRlk71y-3soPem_OtAb61eh4w7muRho0jM2XYNW3Zq9CiF4KOO_krK_7F8LaxYoLG1iCqJZ9WcbP142-u_x2jaZPP2OPQAIxzQhK6e2OsW0wVm1KHkl-3smffVUtzyZnspDj1w8XGoqisFlo3NG1IywFoZOiXsahK7iYrUBw1', 'action' => 'calendar/events/save-event', 'redirect' => '8c72e3555cfac47339740f110c401b0fc79eaec54d4d774678c62efc7213644ccalendar/events', 'siteId' => '1', 'calendarEvent' => [ 'calendarId' => '2', ], 'title' => 'Test', 'event_builder_data' => '{"dates":{"start":1657634400,"end":1657638000},"allDay":false,"interval":1,"multiDay":false,"repeats":false,"freq":"DAILY","byDayInterval":0,"byDay":["TU"],"byMonthDay":[12],"byMonth":[7],"endRepeat":{"type":"forever","date":1657670399,"count":1},"selectDates":[],"exceptions":[]}', 'fields' => [ 'timeBlocks' => '', 'eventThema' => '', 'text' => '', 'room' => '', 'location' => '', 'onlineEventExternalUrl' => [ 'type' => 'url', 'value' => '', ], 'onlineEventPassword' => '', 'eventfrogId' => '', 'reservation' => '', 'cancelled' => '', 'bookingDeadline' => '1', 'form' => '', 'solidarityPrice' => [ 'locale' => 'de', 'value' => '', ], 'standardPrice' => [ 'locale' => 'de', 'value' => '', ], 'budgetPrice' => [ 'locale' => 'de', 'value' => '', ], 'paymentOptions' => '', 'externalBookingAdddress' => '', 'maxSeats' => [ 'locale' => 'de', 'value' => '0', ], 'reservedSeats' => [ 'locale' => 'de', 'value' => '0', ], 'bookingInfo' => '', 'dateSubmissions' => '', 'metaDescription' => '', ], 'slug' => 'test', 'author' => [ '1', ], 'postDate' => [ 'date' => '12.07.2022', 'timezone' => 'Europe/Zurich', 'time' => '14:35', ], 'enabled' => '1', 'enabledForSite' => '1', ];

$_COOKIE = [ '_ga' => 'GA1.2.807695400.1565735734', '1031b8c41dfff97a311a7ac99863bdc5_username' => 'e20d51d9795fce6c49fd4c4e477f41a2da01c3575bcb92bbb2f1eada908e963ba:2:{i:0;s:41:"1031b8c41dfff97a311a7ac99863bdc5_username";i:1;s:8:"odegiuli";}', '__stripe_mid' => '516fca8d-fddc-498d-872a-b9831fe0b1db4e9356', 'cookieconsent_status' => 'dismiss', 'form_posted_1' => '1652969444', 'Craft-f1f3242c-0a9c-4e69-a7b0-fa2ea0b4023b:siteId' => '1', '_gid' => 'GA1.2.1504459372.1657548811', 'CraftSessionId' => '54d6f9af931122725aff5847883452a4', '1031b8c41dfff97a311a7ac99863bdc5_identity' => '80a76a50989dc4cc4dbd2325540e1e789ec52fe06be793c568e059610b8d59dca:2:{i:0;s:41:"1031b8c41dfff97a311a7ac99863bdc5_identity";i:1;s:159:"[1,"[\"iCl5FkQ87PKdN9ShxFtXnApAUGoiE_A4vRhsCFQxO-zjL3FvzspHuPv1jAS-508riYs8nIbnfH421kjSMk01XJ9byS05cRCxYFft\",null,\"d3d4068a11f4e0f44e4527b12fc4b98f\"]",3600]";}', 'CRAFT_CSRF_TOKEN' => 'd1103b5f7e2fc32f304a8c63d8a0de581d683d9e2b5360b4d99c2b8087c5a7d3a:2:{i:0;s:16:"CRAFT_CSRF_TOKEN";i:1;s:147:"i4l1yBiyNHxHOSPnH2A50TooR1yIk4Z4ejjG5miC|e948ea095794c0098847e7d47be2cbabad157fb536756663e0e98fcf42e1614di4l1yBiyNHxHOSPnH2A50TooR1yIk4Z4ejjG5miC|1";}', ];

$_SESSION = [ 'bd62416aa8538ede709019a5e113eea5flash' => [ 'calendar_event_saved' => -1, ], '1031b8c41dfff97a311a7ac99863bdc5token' => 'iCl5FkQ87PKdN9ShxFtXnApAUGoiE_A4vRhsCFQxO-zjL3FvzspHuPv1jAS-508riYs8nIbnfH421kjSMk01XJ9byS05cRCxYFft', '1031b8c41dfff97a311a7ac99863bdc5id' => 1, 'authKey' => '["iCl5FkQ87PKdN9ShxFtXnApAUGoiE_A4vRhsCFQxO-zjL3FvzspHuPv1jAS-508riYs8nIbnfH421kjSMk01XJ9byS05cRCxYFft",null,"d3d4068a11f4e0f44e4527b12fc4b98f"]', '1031b8c41dfff97a311a7ac99863bdc5expire' => 1657632944, 'duration' => 3600, 'calendar_event_saved' => true, ];`

thank you for looking at it

greetings omar

mudechs commented 2 years ago

Update: this error occurs only if i forget to select a required related entry. to explain: every calendar event has a related event topic which has to be selected. on my testserver i get the normal info that i forgot to select a mandatory field. but on the liveserver i get a internal server error as posted above.

Versions on my Dev-Server: Craft CMS 3.7.43 Calendar 3.3.12 PHP 8.0.20 MySQL 10.3.32

mudechs commented 2 years ago

Update: if i create a new entry and choose the mandatory topic to a event and save it all is fine. if i reopen the just created entry, try to remove the topic and save again, the topic is still chosen in the field. it means, that i can not remove a related field entry and resave it. it still remains selected.

kjmartens commented 2 years ago

Very sorry for the delay @mudechs. I can duplicate this in my testing as well. We'll need to make sure it doesn't error like that. However, if the relation field is required, it does make sense that things should not push through... we'll update/fix our validation to appear like typical validation, rather than breaking down though. 🙂

mudechs commented 2 years ago

hey @kjmartens ! ty so much for your answer. i'm happy you understood my bad english :-)

kjmartens commented 2 years ago

This is resolved now in Calendar 3.3.15 and 4.0.0-beta.8 🙂