• I have created a Python script which automatically updates the match scores in the database table pool_wp_matches. After this I wanted to automatically calculate the standings with the wp-cli command wp football-pool calc.

    Unfortunatelly, I am getting the following Dutch error, which I can not resolve, since I am running WordPress on a Synology NAS.

    Het lijkt erop dat je PHP-installatie geen MySQL-extensie heeft en die is noodzakelijk om WordPress te kunnen gebruiken.

    Is there another way to calculate the standings. Previously you told me that there are JavaScript commands to do this. But I never found out which. I would like to let my Python script start a calculation. Any help would be very much appreciated, since I am trying to set this up since the World Cup in 2014.

    • This topic was modified 5 years, 10 months ago by harmenzon.
    • This topic was modified 5 years, 10 months ago by harmenzon.
Viewing 15 replies - 1 through 15 (of 20 total)
  • Plugin Author AntoineH

    (@antoineh)

    Strange error. Is this wp-cli that is causing this?

    Anyway, there is a javascript function calculate_score_history() that does AJAX requests until the calculation ends. This function is in the assets/admin/admin.js file. Maybe you can rewrite this in python.

    Thread Starter harmenzon

    (@harmenzon)

    Thanks for your support.

    I do not believe it is the wp-cli that is causing this. For example if I use the command wp db check than all seems to be fine. I would really like to use wp-cli. So maybe we can debug this together?

    Below the outcome of the command wp --info --debug:

    
    Debug (bootstrap): No readable global config found (78.102s)
    Debug (bootstrap): No project config found (78.357s)
    Debug (bootstrap): argv: /usr/local/bin/wp --info --debug (78.415s)
    Debug (bootstrap): Running command: cli info (78.428s)
    OS:     Linux 3.2.40 #15284 Sat May 19 04:36:51 CST 2018 armv7l
    Shell:  /bin/sh
    PHP binary:     /usr/bin/php
    PHP version:    5.6.11
    php.ini used:   /etc/php/php.ini
    WP-CLI root dir:        phar://wp-cli.phar
    WP-CLI vendor dir:      phar://wp-cli.phar/vendor
    WP_CLI phar path:       /volume2/web/wordpress
    WP-CLI packages dir:
    WP-CLI global config:
    WP-CLI project config:
    WP-CLI version: 1.5.1
    
    • This reply was modified 5 years, 10 months ago by harmenzon.
    • This reply was modified 5 years, 10 months ago by harmenzon.
    Plugin Author AntoineH

    (@antoineh)

    Hmm, don’t really have a clue. This looks like a problem in the configuration of your box and/or php install. But I am not a sysadmin or linux expert.

    I have wampserver on a windows laptop and it is a miracle that I even got wp-cli running on my machine πŸ˜€

    Thread Starter harmenzon

    (@harmenzon)

    Understood. Then I would like to try the second approach, with the calculate_score_history() function. I created a html page and tried to call the function.
    If that would work, then I can call that html page from Python. But I seem to be missing some defines like FootballPoolAjax and ajaxurl. Hope you can help me out and thanks again for your time.

    
    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>Page Title</title>
        <meta name="viewport" content="width=device-width, initial-scale=1">
    </head>
    <body>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    
        <script src="admin.js"></script>
    
        <script>
            console.log(FootballPoolAdmin);
            FootballPoolAdmin["calculate"]();
        </script>
    </body>
    </html>
    
    • This reply was modified 5 years, 10 months ago by harmenzon.
    Plugin Author AntoineH

    (@antoineh)

    ajaxurl is a standard WP javascript var and FootballPoolAjax is a var I set with wp_localize_script() to set some messages and other global vars.

    You can copy & paste the correct values from the generated source of an admin page, e.g.

    <script type='text/javascript'>
    var FootballPoolAjax = {"fp_recalc_nonce":"f91bd73dbc","colorbox_close":"close","colorbox_html":"","error_message":"Something went wrong while (re)calculating the scores. See the <a href=\"?page=footballpool-help#ranking-calculation\">help page<\/a> for details on solving this problem.","error_label":"Error message","chosen_no_results_text":"Oops, nothing found!"};
    
    var ajaxurl = '/wp-admin/admin-ajax.php';
    </script>

    You may need to change the ajaxurl path to match your install.
    But when I look at it, the nonce value may also cause a problem. Not sure if you can copy that from the source as it will change. You will have to try.

    Thread Starter harmenzon

    (@harmenzon)

    Thanks. Almost there I hope… I copied the FootballPoolAjax var from the source and got passed some initial errors. Now the following error shows. Any suggestions?

    
    admin.js:127 Uncaught TypeError: $.colorbox is not a function
        at Object.success (admin.js:127)
        at u (jquery.min.js:2)
        at Object.fireWith [as resolveWith] (jquery.min.js:2)
        at k (jquery.min.js:2)
        at XMLHttpRequest.<anonymous> (jquery.min.js:2)
    
    Plugin Author AntoineH

    (@antoineh)

    Colorbox is a 3rd party lib I use in the admin to open the popup for the calculation. Source is in the /assets/libs/colorbox folder.

    Thread Starter harmenzon

    (@harmenzon)

    Thanks. Unfortunately, another error pops up. This might not be the way forward…

    
    Uncaught TypeError: e(...).live is not a function
        at at (jquery.colorbox-min.js:4)
        at Function.e.fn.(anonymous function).e.(anonymous function) [as colorbox] (https://services.maptm.nl/intranet/wp-content/plugins/football-pool/assets/libs/colorbox/jquery.colorbox-min.js:4:4621)
        at Object.success (admin.js:127)
        at u (jquery.min.js:2)
        at Object.fireWith [as resolveWith] (jquery.min.js:2)
        at k (jquery.min.js:2)
        at XMLHttpRequest.<anonymous> (jquery.min.js:2)
    

    And this is the code so far:

    
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    
    <script src="wp-content/plugins/football-pool/assets/admin/admin.js"></script>
    	
    <!--<script src="wp-content/plugins/football-pool/assets/libs/chosen/chosen.jquery.min.js"></script>-->
    <script src="wp-content/plugins/football-pool/assets/libs/colorbox/jquery.colorbox-min.js"></script>
    
    <script>
        var FootballPoolAjax = {"fp_recalc_nonce":"ed130dfe9a","colorbox_close":"sluiten","colorbox_html":"","error_message":"Er is iets foutgegaan bij het berekenen van de scores. Bekijk de <a href=\"?page=footballpool-help#ranking-calculation\">helppagina<\/a> voor informatie over hoe je het probleem kan achterhalen.","error_label":"Foutmelding","chosen_no_results_text":"Oeps, niets gevonden!"};
    
        var ajaxurl = 'wp-admin/admin-ajax.php';
        console.log(FootballPoolAdmin);
        FootballPoolAdmin["calculate"]();
    </script>
    
    • This reply was modified 5 years, 10 months ago by harmenzon.
    Thread Starter harmenzon

    (@harmenzon)

    Ok. If I replace live with on within jquery.colorbox-min.js then I get a message that a calculation is already started. Any suggestion?

    
    Berekening scores en stand
    Er is al berekening van de stand bezig. Wacht a.u.b. tot deze is geΓ«indigd voor een nieuwe wordt gestart.
    
    If - for some reason - this message is wrong, see the help page for tips on how to force a calculation start.
    

    And also the next error, but maybe minor:

    
    Uncaught TypeError: g[0].style.removeAttribute is not a function
        at y (jquery.colorbox-min.js:4)
        at n (jquery.colorbox-min.js:4)
        at HTMLDivElement.complete (jquery.colorbox-min.js:4)
        at HTMLDivElement.r.complete (jquery.min.js:2)
        at u (jquery.min.js:2)
        at Object.fireWith [as resolveWith] (jquery.min.js:2)
        at u (jquery.min.js:2)
        at Function.w.fx.tick (jquery.min.js:2)
        at at (jquery.min.js:2)
    
    Thread Starter harmenzon

    (@harmenzon)

    After I forced a calculation within Admin Help, a reload of my calculation html page gives me the response that a calculation is started. Unfortunately, still with an error and the calculation does not seem to complete. Any suggestion?

    
    Uncaught TypeError: bar.progressbar is not a function
        at Object.success (admin.js:143)
        at u (jquery.min.js:2)
        at Object.fireWith [as resolveWith] (jquery.min.js:2)
        at k (jquery.min.js:2)
        at XMLHttpRequest.<anonymous> (jquery.min.js:2)
    
    Thread Starter harmenzon

    (@harmenzon)

    Success!!
    I made a copy of the admin.js file and commented out the bar. Now it works.
    Not sure if it will keep on working since "fp_recalc_nonce":"f91bd73dbc" keeps on changing. Thanks for your help so far!

    Plugin Author AntoineH

    (@antoineh)

    Progressbar is part of jQuery UI. Not really needed, just a nice visual indicator of the state of the calculation. But also easily fixed by loading that lib.

    Anyway, I think the nonce will be a bigger problem. If you are just doing this on your local install, you may consider removing this extra check from the calculation file (/admin/class-football-pool-admin-score-calculation.php).

    Line 59 contains this code:
    $nonce = wp_create_nonce( FOOTBALLPOOL_NONCE_SCORE_CALC );

    Think you can also set it to a static string there. Just make sure you don’t forget to change this again after every upgrade of the plugin.

    Or if this doesn’t work, then maybe just comment the checks for the referer above line 59.

    @antoine : im installing wp cli for windows. Hope it will work because normally its for unix env’s πŸ™‚

    @harmenzon : Can you pass me the html page that worked in the end to trigger the calculation please?

    Plugin Author AntoineH

    (@antoineh)

    im installing wp cli for windows. Hope it will work because normally its for unix env’s πŸ™‚

    It’s working on my win laptop πŸ™‚

    Thread Starter harmenzon

    (@harmenzon)

    @deshke: It was also very easy for me to set up wp-cli on Windows (xampp). For me it was not possible to set it up on unix (synology). I would recommend the wp-cli approach. Just let me know if that fails, then I will share the code that I have so far.

Viewing 15 replies - 1 through 15 (of 20 total)
  • The topic ‘Automated recalulation of scores’ is closed to new replies.