Jump to content

TomPich

Members
  • Posts

    101
  • Joined

  • Last visited

  • Days Won

    3

Posts posted by TomPich

  1. OK, so it’s not Stripe.

    Every now and then, specialy in the middle of the night, I have the following exceptions logged:

    2024-11-24 01:25:55    ?    ?    Unable to load Modules - SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO) (in /wire/core/WireDatabasePDO.php line 505)
    2024-11-24 01:25:55    ?    ?    SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO) (in /wire/core/WireDatabasePDO.php line 505)

    Somehow, PW wants to use the local db credencial, even though it’s the online website. No error has been reported by my client, and I can’t see no error neither.
    Any clues about what this is about?

    Any help would be really appreciated.

    Thanks

  2. Hi,

    Updating CSS – Processwire let you handle CSS the way you want directly in file(s). So yes, you will have to manually edit the CSS.

    I cannot help you with Form Builder specifically, as I don’t use it. But the general behaviour of PW with form is the same as default behaviour: if not specified otherwise, a form will send the form data with GET to the current URL when you press submit.
    So you have to check what method is used on your form (GET or POST) and to which URL the data are sent.
    With the elements you provided, I would say the data are sent with JS by fetch. So try to locate the script that handle this to see what happen when the form is submitted.

    When you know where your data are sent, there is two possibilities:
    • either it’s a existing page, so get the template php file of the corresponding page, and you see what happens with the data.
    • or (more probably in your situation, as it seems to be a JS submit), it’s an endpoint that has been created via a hook (check your init.php file in the site folder) to handle the data.

    Hope this helps.

  3. I think I got it.
    I use Stripe on this website. And to confirm webhook, there is a POST request sent by Strip to confirm payment.
    When I do a test on the local website, Stripe sends the request to the online website, but with a reference to the local url...
    So PW cache is not involved here, I guess...

  4. 14 hours ago, froot said:

    I'm not sure what you mean here…

    5 hours ago, virtualgadjo said:

    when using webpack, as it works with node, borwsers do not understand the import links the way  a machine does
    don't know if it's the real answer...

    That’s my point. When using webpack on a website, you have to map the includes with the corresponding node_module folders. It does not find them automatically. That has to be done in the webpack.config.js.

    Otherwise (which is the solution I choose), you have to write the full path to the file to include (and the right version of it), something like "../node_module/@fullcalendar/core/index.global.js" or whatever file that provides the final "exports".

    Hope it will be usefull.

    • Like 1
  5. Hello guys,

    I have a strange and silent error on a PW website that I cannot figure out.
    It happens only online (not in local).
    It’s a database connexion error, and I never saw it on the website, it just appears in the logs.

    On localhost, the url is mfw-ut-inscription-2024. It’s a different one online, of course.
    I have my credentials for databases (internal and external databases) in config.php, which look like:

    // PW database
    if ( in_array($_SERVER["HTTP_HOST"], ["my-distant-website.com"])) {
        $config->dbName = 'xxx';
        $config->dbUser = 'xxx';
        $config->dbPass = 'xxx';
    } else {
        $config->dbName = 'xxx';
        $config->dbUser = 'root';
        $config->dbPass = '';
    }
    
    // External database
    if ( in_array($_SERVER["HTTP_HOST"], ["my-distant-website.com"])) {
        $config->gestiondbName = 'xxx';
        $config->gestiondbUser = 'xxx';
        $config->gestiondbPass = 'xxx';
    } else {
        $config->gestiondbName = 'xxx';
        $config->gestiondbUser = 'root';
        $config->gestiondbPass = '';
    }

    Everything works perfectly. But every day, I get new errors logged in the errors.txt log file (from the online website).

    2024-11-10 12:41:56    ?    https://mfw-ut-inscription-2024/
    Error:  Exception: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO)
        (in /home/joko4944/domains/staging.ut-inscription.com/wire/core/WireDatabasePDO.php line 505)
    #0 /home/joko4944/domains/staging.ut-inscription.com/wire/core/WireDatabasePDO.php(505): PDO->__construct()
    #1 /home/joko4944/domains/staging.ut-inscription.com/wire/core/WireDatabasePDO.php(872): ProcessWire\WireDatabasePDO->pdoWriter()
    #2 /home/joko4944/domains/staging.ut-inscription.com/wire/core/WireSaveableItems.php(219): ProcessWire\WireDatabasePDO->prepare()
    #3 /home/joko4944/domains/staging.ut-inscription.com/wire/core/Wire.php(416): ProcessWire\WireSaveableItems->___load()
    #4 /home/joko4944/domains/staging.ut-inscription.com/wire/core/WireHooks.php(968): ProcessWire\Wire->_callMethod()
    #5 /home/joko4944/domains/staging.ut-inscription.com/wire/core/Wire.php(484): ProcessWire\WireHooks->runHooks()
    #6 /home/joko4944/domains/staging.ut-inscription.com/wire/core/Fields.php(285): ProcessWire\Wire->__call()
    #7 /home/joko4944/domains/staging.ut-inscription.com/wire/core/Fields.php(172): ProcessWire\Fields->getWireArray()
    #8 /home/joko4944/domains/staging.ut-inscription.com/wire/core/ProcessWire.php(625): ProcessWire\Fields->init()
    #9 /home/joko4944/domains/staging.ut-inscription.com/wire/core/ProcessWire.php(578): ProcessWire\ProcessWire->initVar()
    #10 /home/joko4944/domains/staging.ut-inscription.com/wire/core/ProcessWire.php(315): ProcessWire\ProcessWire->load()
    #11 /home/joko4944/domains/staging.ut-inscription.com/index.php(52): ProcessWire\ProcessWire->__construct() #12 {main}

    So that’s very very strange because:
    (1) the url is *not* the url of the online website (although the errors only show up online).
    (2) at some point, PW tries to connect to my local databases (and of course it can’t, because it’s online)
    (3) I never noticed anything wrong on the onine website, nor my client...

    The local url (mfw-ut-inscription-2024) only appears at 4 places in the website files:
    Three times in config.php
    • $config->httpHosts = array('mfw-ut-inscription-2024', "my-distant-website.com");
    • twice in something like: if ($_SERVER["HTTP_HOST"] === 'mfw-ut-inscription-2024' ){/* some scret keys for some services */}

    and one last time in a hook in init.php: $is_local = $this->config->domain === "mfw-ut-inscription-2024";

    So I can’t understand how the online website can detect a session @ https://mfw-ut-inscription-2024/.
    Can this be due to some cache file? I only use the basic cache system of PW and no template is cached.

    Any clue or advice would be welcome. 😊
    Thank you

  6. Hello friends,

    I stumbled upon a problem that is harder to solve that I thought.
    On a template, the user can upload a file. The description of the file is used in the front as text for the download button.
    The client asked me to have a default description for this field (Communiqué).
    So I started to play with some hooks (in admin page), mainly addHookAfter InputfieldFile::processInputFile
    This is where I am for now...

    $wire->addHookAfter('InputfieldFile::processInputFile', function (HookEvent $event) {
    	$field = $event->object;
    	if ($field->attributes["name"] === "postFile") {
    		// fill the file description with "Communiqué de presse
    		// but I can’t figure out how to do that
    	};
    });

    Any help?
    Thanks!

  7. In the Selectors class definition, Ryan wrote that the protected property "selectorStr" there only for debugging.
    I tried with $selectors->get("selectorStr") and it doesn’t work neither.
    So if I really need that string (and couldn’t store it earlier in the process), I would create a class that extends Selectors an allow selectorStr exposure...

  8. 9 hours ago, fliwire said:
    // suffix is Repository not Repo.
    
    $classLoader->addSuffix("Repository", __DIR__ .  '/classes/Repository');

    Yes... I tried Repository first, then I tested with another suffix (Repo), and it didn’t change anything (and I then commented it out...). The addnamespace does all the job.
    So I don’t get what this addSuffix does. My guess is that it allows better performance when there are a lot of classes, pointing out the sub-folder to look into. But then, so does the

    namespace ProcessWire\Repository;
    

    I can't figure it out...

  9. Hey guys,
    @da², @fliwire, thank you for your help. It pushed me in the right direction.
    I got my things done and wanted to share with whoever would find that useful.
    Here was my need: a specific folder to store some classes, usable easily across templates (ie "use Class" and not "include ...".
    These classes wouldn’t fit (IMO) into a DefaultPage class for separation of concerns matter.
    And I didn’t want to try to develop a module, seemed an overkill and time is running...

    I decided to store my custom classes files into some subfolders of the /site/classes folder. At first, I used a /site/src folder (and it worked), but as the classes folder already exists, I thought it made more sense to use this folder. This is my architecture

    ├── site/
    │   ├── assets
    │   ├── classes/
    │   │   ├── Repository/
    │   │   │   ├── AbstractRepository.php
    │   │   │   └── ContactRepository.php
    │   │   ├── DefaultPage.php
    │   │   ├── HomePage.php
    │   │   └── Utils.php
    │   ├── modules
    │   └── templates
    └── wire

    For autoloading use PW autoloader, in put in init.php

    $classLoader = $wire->classLoader;
    $classLoader->addNamespace("ProcessWire", __DIR__ .  '/classes');

    Then the magic happens. My ContactRepository.php, for example :

    namespace ProcessWire\Repository;
    
    use ProcessWire\Utils;
    
    class ContactRepository extends AbstractRepository
    {
    	// my stuff here...
    }

    and when I need it in a template file :

    namespace ProcessWire;
    use ProcessWire\Repository\ContactRepository;
    
    $contactRepo = new ContactRepository;
    $speakers = $contactRepo->getAllSpeakersAndModerators();

    Remarque:
    In the init.php file, I tried with and without

    $classLoader->addSuffix("Repo", __DIR__ .  '/classes/repositories'); // does not change anything
    $classLoader->addPrefix("Repo", __DIR__ .  '/classes/repositories'); // does not change anything

    I can't really grasp in which situation this useful, and the doc is quite short... 😅
    So with this file structure, I can really get a step further in logic handling and code maintenance.
    Hope someone will find this useful.
    Cheers

    • Like 4
  10. Hi guys,

    I know this has been asked already a few times here, but I couldn’t find a working solution for me...
    Working on a quite big project and I feel it can get messy quite easily. I need to tidy my code a little but.

    So here is the situation: I have quite a lot of data handling to do in the front side of my website. This involves querying on an external DB and processing the data.

    I started to write some methods in a DefaultPage class and that works well, but this will end with a very big file with tens of methods not related to the same logic.
    What I would like, is to have a src/ folder in my site/ folder, with all the custom classes in relevant subfolders.

    I tried this:

    // in site/init.php
    $namespace = 'ProcessWire\\App';
    $classLoader = $this->wire('classLoader');
    if (!$classLoader->hasNamespace($namespace)) {
        $srcPath = 'src/'; // target folder is /site/src
        $classLoader->addNamespace($namespace, $srcPath);
    }

    Inside this site/src/ folder, there is a MyClass.php file, with the class MyClass

    namespace App;
    
    class MyClass
    {
        const hello = "hello";
    }

    And in my template file:

    namespace ProcessWire;
    use App\MyClass;
    <?= MyClass::hello  ?>

    But I can’t get class loaded... 😔
    I tried variation with namespace and use, but it didn’t work...
    Any help please ?
    Thank you!

     

  11. Hey Robin,
    Thanks for your work. It looks like this module would fit my need for something – could you confirm please?
    I need to retrieve data from an external database (I’m okay with thay), something like an array of id => value.
    I’d like the select options to show the value, and then store the pair id / value in the field.
    Can I do that with this module?

  12. Great. That works well.
    For whom it could be useful, this is the code of my DefaultPage class:

    class DefaultPage extends Page {
    
    	public WireDatabasePDO $dblfa;
    
    	public function __construct(Template $tpl = null)
    	{
    		parent::__construct($tpl);
    		$this->dblfa = new WireDatabasePDO(/* credentials */);
    	}
    
    	public function getParticipants()
    	{
    		$request = "SELECT * FROM participants";
    		$query = $this->dblfa->query($request);
    		$items = $query->fetchAll(\PDO::FETCH_ASSOC);
    		$query->closeCursor();
    		return $items;
    	}
    }
×
×
  • Create New...