Jump to content

da²

Members
  • Posts

    240
  • Joined

  • Last visited

  • Days Won

    3

Posts posted by da²

  1. On 3/25/2024 at 4:22 PM, hellomoto said:
    Cannot modify header information - headers already sent by (output started at /pw/bootstrap/index.php:5) in /pw/index.php on line 41

    @hellomoto It's a common error. You are outputting data before the headers, but headers must be the first thing to output.

    Headers are sent by ProcessWire, but you echo something before to include PW:

    $boot = realpath($boot); echo $boot; // DO NOT echo something...
    require_once $boot;// $pw_dir.'/index.php'; // ...BEFORE PW sent headers.

    Also why do you use this code and not a simple include at start of file?

    include __DIR__ . "/../index.php";
  2. On my side I use a script to upload site, there's 2 parts:

    - A Ant project that synchronizes some folders/files from the source code to a "target" directory, add a version number and transpile SCSS to CSS, TypeScript to JS...
    - A bash script that runs the Ant project, and if no error, use rsync to synchronize only changed files with the production server. It uses a file listing exclusions so I'm sure the site/config.php will never be uploaded, like the sessions or the cache.
    This script is a Linux one because Linux have those powerful integrated tools like rsync, but I'm running Windows and executing the script with Microsoft Linux WSL.
    I have another bash script for staging server, it's the same as for production except it also pushes a clean version of my local ProcessWire database to the staging server.

  3. Hello, updating PHP means you need to install a newer version of PHP, it's not directly related to ProcessWire in first instance. It depends of your OS (Windows, Linux), it also depends if this is a shared host or a dedicated server. In a shared host you usually have an administration interface provided by your hosting service to manage your server. In a dedicated server you generally do everything yourself.

    About ProcessWire you have to check that the currently installed version is compatible with the PHP version you plan to install. Probably it won't be OK because you talk about years. If you plan to install PHP 8+ you'll also need to upgrade PW.

    • Like 2
  4. 22 minutes ago, August said:

    I wonder how you know...

    @August Because I'm using big tables that are filled dynamically and locked in admin and the result is a horizontal scrollbar on the whole page:

    image.thumb.png.1d15702ce5ffc23b427dbad7343b740a.png

    22 minutes ago, August said:

    Let's hope Ryan takes a moment to do this - until then I'll always have to modify this file, which I don't really want to do..

    In that case I create a git patch file, so if I update PW to a version that doesn't fix the issue, I then apply the patch. I also document on my wiki what's the goal of each patch.

  5. If you look into InputfieldRepeater.module, in method ___processInput() :

    if($numErrors || $numRequiredEmpty) {
      $this->error(sprintf($this->_('Errors in “%s” item %d'), $this->label, $key + 1));
      if(!$page->hasStatus(Page::statusUnpublished)) $this->numRequiredEmpty += $numRequiredEmpty;
      $openIDs[$page->id] = $page->id; // force item with error to be open on next request
    } else if(isset($openIDs[$page->id])) {
      unset($openIDs[$page->id]);
    }

    It opens items with an error, but our hook is executed after this, so this code doesn't know at this time that this item has an error (and "before" hook is not working at all).

    You see that $openIDs is used to remember which items to open, and at bottom of this function it stores it in session:

    if($_openIDs !== $openIDs) $this->wire()->session->setFor($this, 'openIDs', $openIDs); 

    So it looks like there's at least a way to achieve your goal by directly updating this session variable:

    wire()->addHookAfter("Inputfield(name=championshipRoundRepeater)::processInput", function (HookEvent $event) {
        /** @var InputfieldRepeater $inputfieldRepeater */
        $inputfieldRepeater = $event->object;
        $openIDs = wire()->session->getFor($inputfieldRepeater, 'openIDs') ?? [];
    
        /** @var InputfieldWrapper $wrapper */
        foreach ($inputfieldRepeater->getWrappers() as $repeaterItemId => $wrapper) {
            /** @var Inputfield $itemField */
            $itemField = $wrapper->getByName("title_repeater$repeaterItemId");
            $itemField->error('this is an error');
            $openIDs[$repeaterItemId] = $repeaterItemId;
        }
        wire()->session->setFor($inputfieldRepeater, 'openIDs', $openIDs);
    });

    I don't like this solution because it is strongly dependent of a the ___processInput() private implementation. Maybe there's a cleaner way to work with this, I don't know... If no, maybe it would be a good idea to add a hookable method ___checkForItemErrors(InputfieldWrapper $repeaterItem):void, called from ___processInput()?  @ryan

  6. I don't how to do this, but by exploring HTML source of the repeater items in admin page (browser dev tools), looking InputfieldWrapper API and InputfieldRepeater API, and var_dumping things in a hook, I found a way.

    image.thumb.png.7d052acd0f4a2363fc2e322787982a13.png

     

    self::addHookAfter("Inputfield(name=championshipRoundRepeater)::processInput", function (HookEvent $event) {
        /** @var InputfieldRepeater $inputfieldRepeater */
        $inputfieldRepeater = $event->object;
    
        /** @var InputfieldWrapper $wrapper */
        foreach ($inputfieldRepeater->getWrappers() as $repeaterItemId => $wrapper) {
            /** @var Inputfield $itemField */
            $itemField = $wrapper->getByName("title_repeater$repeaterItemId");
            $itemField->error('this is an error');
        }
    });

    image.thumb.png.eee3c64299c9d1d81061446e558ff9ce.png

    • Like 1
  7. 4 minutes ago, MarkE said:

    I don’t know what the Cargo pagebuilder is like, but the website isn’t great

    Yes the site is terrible and full of bugs, I even had page freezes, not sure they really want their CMS to be used. 😄

    • Haha 1
  8. I reported this behavior to the dev who created the Twig module for PW and the given solution is to use get().

    I hate some of the Twig behaviors and consider switching to another solution in the future.

    Another thing to know is that, when you call page.noIndex, if not found Twig will also call method page.getNoIndex(), property page.getNoIndex and a bunch of other calls like that...

    • Like 1
  9. @fruid Use custom page classes.

    In site/classes:

    <?php namespace ProcessWire;
    
    class UserPage extends User
    {
      public function getMessages(): PageArray
      {
          return wire()->pages->find('template=message, receiver=' . $this->id);
      }
    }

    Be sure to enable it in site/config.php

    $config->usePageClasses = true;
    • Like 4
  10. Just to add another solution to the original question, this is how I hide not editable pages in admin tree:

    $this->addHookAfter('Page::listable', isPageListable(...));
    
    function isPageListable(HookEvent $event): void
    {
        if ($event->page->path == "/")
            $event->return = true;
        else
            $event->return = wire()->user->hasPermission("page-edit", $event->page);
    }

     

    • Like 1
  11. I was just joking about how you wrote the "Hit CMD+Enter" like if the answer is sure, don't take my message too seriously. 🙂

    I wouldn't event trust the answer about rw-r--r--, because very often ChatGPT is absurdly wrong and answers the exact opposite of the truth. Then I correct it and next answer is good. So if I need to check the AI answers on the web, it's faster not to ask the AI and directly go on the web/documentation. Most of the time I use AI when I can't find answer with traditional ways.

    14 minutes ago, cwsoft said:

    I do like to refine some of my code in little steps or to prompt the AI for specific questions on my own code, like I did in the past as part of a development team with my human colleagues. Thats where AI is really not so bad in my opinion, at least if you are working alone on projects and there are no human colleagues you could ask. 

    This part is more interesting IMO, discussing about architecture of your own code, things you can refactor, design patterns you can use... It can be a way to improve faster as a developer. I'm also working alone, and have worked in the past in a team that used to do regular code reviews.

    • Like 3
×
×
  • Create New...