Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Admin Dashboard Plugin Updates Available Tab #1108

Closed
SemperFiWS opened this issue May 24, 2016 · 16 comments
Closed

Admin Dashboard Plugin Updates Available Tab #1108

SemperFiWS opened this issue May 24, 2016 · 16 comments
Assignees
Milestone

Comments

@SemperFiWS
Copy link
Contributor

See pull request - #1107

For my plugins, I already display if a new version is available on the plugin configuration page
e.g.
image

The problem with that is that once a store owner has a configured a plugin, they will very rarely revisit the plugin configuration page.
Therefore if a new version of a plugin is available, they don't know about it.

So I came up with one method that could be used by everyone - 3rd party and CubeCart - to display this information in a new tab on the admin dashboard.
e.g.
image

Once the code changes outlined in the pull request are implemented, utilizing this is pretty straight forward.

  1. Implement a 'version check' text file for the plugin somewhere on your server.
    e.g.
    https://www.semperfiwebservices.com/version-check/cc6-plugins/SFWS_Site_Testimonials.txt
  2. Add the 'admin.dashboard.plugin_updates_available' hook reference to your plugin's config file.
    e.g.
    <hook trigger="admin.dashboard.plugin_updates_available" enabled="1"><![CDATA[Admin Dashboard Site Testimonials Plugin Update Available]]></hook>
    Replacing the plugin name above with the name of your plugin.
  3. Add the 'admin.dashboard.plugin_updates_available' hook itself in your plugins hooks directory.
    e.g.
<?php
if(!defined('CC_DS')) die('Access Denied');

$plugin_config_file = CC_ROOT_DIR."/modules/plugins/SFWS_Site_Testimonials/config.xml";
$plugin_href = $glob['adminFile'].'?_g=plugins&type=plugins&module=SFWS_Site_Testimonials';

$plugin_xml = new SimpleXMLElement(file_get_contents($plugin_config_file));
$plugin_version = (string)$plugin_xml->info->version;
$plugin_folder = (string)$plugin_xml->info->folder;

if ($request = new Request('www.semperfiwebservices.com', '/version-check/cc6-plugins/SFWS_Site_Testimonials.txt')) {
    $request->skiplog(true);
    $request->setMethod('get');
    $request->cache(true);
    $request->setSSL(true);
    $request->setUserAgent('CubeCart');
    $request->setData(array('plugin_version' => $plugin_version));
    if (($response = $request->send()) !== false) {
        if (version_compare(trim($response), $plugin_version, '>')) {
            $plugin_updates_list[$plugin_folder] = array(
                'plugin_href' => $plugin_href,
                'plugin_name' => (string)$plugin_xml->info->name,
                'plugin_creator_href' => (string)$plugin_xml->info->homepage,
                'plugin_creator_name' => (string)$plugin_xml->info->creator,
                'plugin_installed_version' => $plugin_version,
                'plugin_current_version' => $response,
            );
            ++$plugin_updates_available;
        }
    } 
}

You only need to alter:

  • the '$plugin_config_file' so it points to your plugins config.xml file
  • the '$plugin_href' variable to reflect your plugins admin configuration URL
  • the '$request' variable so the URL is that of the version check text file for the plugin
@briansandall
Copy link
Contributor

briansandall commented May 24, 2016

That's pretty slick, I like it.

One improvement I'd like to see is to rather than checking each plugin every single page load, have it set up as a daily CRON job run by CubeCart in the background with the option to 'check manually' at any time if desired. Perhaps add an option for 'real time update checking' for those that want it.

Another small thing that isn't necessarily precluded by your example code would be to include the URL of the version check file in the plugin's XML description; then rather than each plugin writing similar code, CC could simply iterate over the plugins and make the appropriate calls itself.

EDIT: Of course, if it wasn't checked at page load, there would need to be some other storage mechanism in order to display the results of the update check, probably in the database.

@SemperFiWS
Copy link
Contributor Author

All very good suggestions Brian.

A couple of changes based off your suggestions...

File: config.xml

  <info>
    <uid>sitetestimonials@semperfiwebservices.com</uid>
    <type>plugins</type>
    <folder>SFWS_Site_Testimonials</folder>
    <name><![CDATA[Site Testimonials]]></name>
    <description><![CDATA[Site Testimonials Plugin By SemperFiWebServices.]]></description>
    <version>1.0.0</version>
    <minVersion>6.0.0a</minVersion>
    <maxVersion>6.0.*</maxVersion>
    <creator><![CDATA[SemperFiWebServices]]></creator>
    <homepage><![CDATA[http://www.semperfiwebservices.com]]></homepage>
    <version_check_url><![CDATA[www.semperfiwebservices.com/version-check/cc6-plugins/SFWS_Site_Testimonials.txt]]></version_check_url>
  </info>

Adds the 'version_check_url' variable into the plugins config.xml file.

File: admin.dashboard.plugin_updates_available.php

<?php
if(!defined('CC_DS')) die('Access Denied');

$plugin_config_file = CC_ROOT_DIR."/modules/plugins/SFWS_Site_Testimonials/config.xml";

$plugin_xml = new SimpleXMLElement(file_get_contents($plugin_config_file));

$plugin_version = (string)$plugin_xml->info->version;
$plugin_folder = (string)$plugin_xml->info->folder;
$plugin_href = $glob['adminFile'].'?_g=plugins&type=plugins&module='.$plugin_folder;
$plugin_version_check_href = (string)$plugin_xml->info->version_check_url;

if (!empty($plugin_version_check_href) && $request = new Request($plugin_version_check_href)) {
    $request->skiplog(true);
    $request->setMethod('get');
    $request->cache(true);
    $request->setSSL(true);
    $request->setUserAgent('CubeCart');
    $request->setData(array('plugin_version' => $plugin_version));
    if (($response = $request->send()) !== false) {
        if (version_compare(trim($response), $plugin_version, '>')) {
            $plugin_updates_list[$plugin_folder] = array(
                'plugin_href' => $plugin_href,
                'plugin_name' => (string)$plugin_xml->info->name,
                'plugin_creator_href' => (string)$plugin_xml->info->homepage,
                'plugin_creator_name' => (string)$plugin_xml->info->creator,
                'plugin_installed_version' => $plugin_version,
                'plugin_current_version' => $response,
            );
            ++$plugin_updates_available;
        }
    } 
}

Now you only need to set the '$plugin_config_file' variable.

I have a couple ideas regarding not firing this hook every time the dashboard page loads.
Once I get this plugin wrapped up, I will circle back to that.

@briansandall
Copy link
Contributor

That's looking better, but I think we can avoid having to manually set any variables - taking a look in admin/sources/plugins.index.inc.php, it has:

$module_paths = glob("modules/*/*/config.xml");
foreach ($module_paths as $module_path) {
    $xml   = new SimpleXMLElement(file_get_contents($module_path));

Adopting a similar approach here would allow the code update checker to automatically check any installed plugins without any effort on the part of plugin makers other than adding the version_check_url data to their config.xml file.

@Noodleyman
Copy link

A standard way to approach this would be fantastic as I am sure we all handle it using our own custom methods at the moment.

@SemperFiWS
Copy link
Contributor Author

SemperFiWS commented May 27, 2016

Agreed completely that a standardized method needs to be implemented.
I also agree that a simple method without using a hook is a better approach.

Dashboard:
image

Manage Plugins
image

Both locations still check on each load rather than only X amount of times per day.
That I think is fine for the manage plugins page, and possibly for the dashboard too.

All plugin creators need to do is add these two lines to the plugins config.xml file:
image

I have attached the code changes to this issue.
Test them out for yourselves and let me know what you think so I can alter the pull request.
Plugin-Updates-Available.txt

@briansandall
Copy link
Contributor

Perfect! This will be extremely helpful for store admins.

Very minor and probably irrelevant nitpick: language string 'introduced' versions should be '6.0.12' or so, not '5.0.0' or '6.0.0'.

@Noodleyman
Copy link

Noodleyman commented May 27, 2016

@abrookbanks
Would it not be better to introduce a "version" field in the marketplace, then use the marketplace data to pull the list into CubeCart periodically for any modules installed. This way there is no dependency on a third party site and can become part of the core CC product easily. That way as/when we release a new update to the marketplace we can update the version field and everybody gets the notification.

@abrookbanks
Copy link
Member

Hey guys... I like this idea a lot. Hopefully get onto it early next week. I'm a bit behind.

@SemperFiWS
Copy link
Contributor Author

I have updated the original pull request with the code posted above, with the correct language entries.

The problem with using a field in the marketplace is that not every plugin is available in the marketplace.
Implementing that as a secondary check however, would be worth implementing.

@abrookbanks
Copy link
Member

I like this idea but I don't like how it's dependant on 3rd party servers and systems. I'd much rather have something tied into the CubeCart extension marketplace.

@Dirty-Butter
Copy link

I was hoping to see this in 6.0.12, but no such luck. It is SO badly needed!!

@abrookbanks
Copy link
Member

I can't until I can figure out a way to do this via the marketplace as primary source.

@abrookbanks
Copy link
Member

This is coded with external sources as primary source which I'm not keen on.

@Dirty-Butter
Copy link

How does Wordpress handle this? I would guess they are coded with external sources, since there are SO many WP plugins, and their system certainly works well.

@abrookbanks
Copy link
Member

I've no idea. It's not very relevant as we only have the data we have to work with. The marketplace doesn't store a version number anywhere and once the plugin is installed there is no way to backtrace it.

We will get it done.

@abrookbanks abrookbanks added this to the 6.1.0 milestone Sep 20, 2016
@abrookbanks abrookbanks self-assigned this Sep 20, 2016
@abrookbanks
Copy link
Member

abrookbanks commented Sep 20, 2016

This has been implemented for 6.1.0 but only for extensions installed via token from the marketplace. #1243

I intend to either remove or more likely suggest developer and merchants choose install token over download after the 6.1.0 release.

@Noodleyman I will be creating the option for downloads/install tokens of commercial extensions before the end of the week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants