Page->update() fails on production, works locally

Hello

This is a weird one…

I have a file which contains many, many lines like this:

Tickets:

11111-111111
22222-222222
33333-333333
44444-444444
55555-555555
66666-666666
77777-777777
88888-888888
99999-999999
00000-000000

The user of my side gets send an email with one such tickets (the one in the first line). This ticket (it is a voucher based system) is ‘burned’ now and has to be removed from the file. So I ‘unset’ the line (I basiscally just want to remove the first line of the Tickets-list. Not sure if there is a better - more Kirby - way…)

This is my code:

    $arr_tickets = $page->tickets()->nl2br()->split('<br>'); //Alle tickets im Array speichern
    $data['ticket'] = $arr_tickets[0]; //Erstes Ticket speichern für E-Mail
    unset($arr_tickets[0]); //Erstes Ticket aus dem Array löschen
    $ubrige_tickets = implode("\n", $arr_tickets); //Das Array zu einem String umformen
    $page->update([ 'tickets' => $ubrige_tickets ]); //Übrige Tickets wieder speichern
    $anzahl_ubrige_tickets = count($arr_tickets); //Anzahl der übrigen Tickets bestimmen

The line $page->update([ 'tickets' => $ubrige_tickets ]); breaks on the real server, on my local machine it works…
I checked the filesystem permissions, they are like this (should be fine):

grafik

An Exception is thrown:

 Kirby \ Exception \ PermissionException (error.page.update.permission)
You are not allowed to update "wlanticket"

I am lost. Do you have any idea where to look?

Carsten

Been thinking about it… This is the .yml-Code of the file in which those Wifi-Vouchers (german: WLAN-Tickets) are stored:

title: Wlan Voucher
columns:
  spalte:
    width: 1/2
    fields:
      tickets:
        type: textarea
        buttons: false

I guess there has to be a better way to store such a list. A more Kirby-way…

On the other hand: It works on my local machine, so it should work…

The permissions are one aspect, file/dir ownerships another. The file is apparently only writeable by the user who owns it. Try to set it to 666 or 664 to verify if write permissions for the group or others are needed. Probably the web server cannot write the file because it do not own it.

even 777 didn’t work, neither on the directory nor on the file itself.

I guess it might be related to this line in the .htaccess

# block text files in the content folder from being accessed directly
RewriteRule ^content/(.*)\.(txt|md|mdown)$ index.php [L]

But… that line is on my local machine as well…
Will test some more now, running out of ideas :slight_smile:

Before calling this method, you need to authenticate/impersonate an user with the correct permissions or the kirby superuser:Permissions | Kirby CMS

1 Like

Aside from the authentication issue, consider storing this data in a more structured way, i.e. in a structure field.

oh man, thank you so much. This worked out of the box.

I was always logged in on my development machine and never on the real server…