I have a plugins system with update notification. The update notification works, but I made some changes so that the script will execute every hour instead of everytime the page loads. This is handled by the (time() + 3600) being written to a check.cfg file. I wanted to to cut down on the page execution time, especially if the user has quite a few plugins installed. Along with this change, I wanted to write the results to the database for each plugin. However, it doesn't get written to the database, and I believe it has something to do with when the check.cfg file is called and/or updated. Below is the code. Any help is greatly appreciated.

        if(!file_exists(PM_CONTENT_DIR . 'check.cfg')) {
            touch(PM_CONTENT_DIR . 'check.cfg');
        }

        $checkFile = file_get_contents( PM_CONTENT_DIR . 'check.cfg', true);

            if((int)$checkFile > time()) {
                /* Do not update */;
            } else {
                $pUpgrade = explode("\n", @file_get_contents( "http://git.plugins.projectpress.org/" . $plugin_info['Plugin Slug'] . ".git/raw/master/" . $plugin_info['Plugin Slug'] . ".txt" ) );

                if($sql1->num_rows == 0 && $plugin['Plugin Slug'] != $r1['plugin_slug'] && $plugin_info['Version'] < $pUpgrade[1]) {
                    $sql2 = pmdb::connect()->insert( DB . 'plugin_updates', 
                                                    array(pmdb::connect()->escape($pUpgrade[0]),
                                                         pmdb::connect()->escape($pUpgrade[1]),
                                                         pmdb::connect()->escape($plugin),
                                                         ),
                                                         'plugin_slug,
                                                         version,
                                                         update_url'
                                                        );
                } else {
                    $sql3 = pmdb::connect()->update( DB . 'plugin_updates', array( 'version' => $pUpgrade[1]), array( 'plugin_slug', $pUpgrade[0] ) );
                }

                $fp = fopen(PM_CONTENT_DIR . 'check.cfg', 'w+');
                fwrite($fp, time() + get_pm_option('plugin_update_time'));
                fclose($fp);
            }

Recommended Answers

All 2 Replies

Member Avatar for LastMitch

@joshmac

However, it doesn't get written to the database, and I believe it has something to do with when the check.cfg file is called and/or updated.

What kind of plugin is this?

You modify the plugin and you can't save the info in the database?

This doesn't work:

$checkFile = file_get_contents( PM_CONTENT_DIR . 'check.cfg', true);

Try to use parse_ini_file():

$checkFile = parse_ini_file('check.cfg');

This is as much as I can help you with this.

Thanks, that did it. They are plugins written for a project management software I developed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.