bobbingwide / oik-batch

Batch interface to WordPress
https://www.oik-plugins.com/oik-plugins/oik-batch
GNU General Public License v2.0
0 stars 0 forks source link

Add logic to update Git based components #34

Open bobbingwide opened 5 years ago

bobbingwide commented 5 years ago

Currently the nested plugin called oik-wp.php is not expected to be activated. I want to test whether or not I can invoke git commands from a Linux hosted Apache server, rather than SSH. If so, then we should be able to implement git pull commands for Git based repos.

bobbingwide commented 5 years ago

Well that was a success for WP-a2z.org.

image

The output shows the result of git status -s. This is basically the same output as we get from SSH run in public_html, public_html/wp-content and any other directory which doesn't have a GIT repo. We get output since the GIT repo is https://github.com/bobbingwide/WP-a2z

If there wasn't a GIT repository we'd get

fatal: Not a git repository (or any of the parent directories): .git

If we're not allowed to run the git command under shell_exec() we'd get some other result. TO BE TESTED on other servers.

So now we can go ahead and write the code to perform git pull within the appropriate folder. Maybe create a form that will support status, remote, pull etc

bobbingwide commented 5 years ago

Having tried the logic on a site hosted with TSOhost I then extended it to check for GIT repos for each installed plugin ( in the plugin directory ) producing a report of plugins which are apparently git repos. In some cases, e.g. where the plugin was uploaded using FTP, the "remote" repository turns out to be inaccessible... \github\bobbingwide\oik-batch instead of https://github.com/bobbingwide/oik-batch. image

Next steps

bobbingwide commented 5 years ago

Having made further progress, rather than hook into oik options > overview the solution should now use its own admin page ( oik_batch ) to implement Git admin. We'll do it for plugins first, then themes and maybe core and mu-plugins... that's a thought.

Note: It takes a reasonable amount of time to perform GIT commands, so we can't really do too many in one server request. The logic to check if a plugin is a GIT repository needs to be quicker. Once a plugin has been identified as a GIT plugin then we can perform a Check action that will invoke more git commands to see if updates are available, and if so apply them.

bobbingwide commented 5 years ago

v1.0.0 has now been installed on wp-a2z.org and Network Activated.

As expected, the checking logic does not work for private repositories which require the username and password to be given. For diy-oik we get the following messages.

remote update: Fetching origin fatal: could not read Username for 'https://github.com': 
No such device or address error: Could not fetch origin

fetch: fatal: could not read Username for 'https://github.com': 
No such device or address

status: On branch master Your branch is up-to-date with 'origin/master'. 
nothing to commit (use -u to show untracked files)

Pull: fatal: could not read Username for 'https://github.com': 
No such device or address
bobbingwide commented 5 years ago

Somehow EDD is now ahead

Remote: https://github.com/bobbingwide/easy-digital-downloads

Current: cad0244 Merge branch 'master' of https://github.com/bobbingwide/easy-digital-downloads

... 

status: On branch master Your branch is ahead of 'origin/master' by 9 commits. (use "git push" to publish your local commits) nothing to commit (use -u to show untracked files)
bobbingwide commented 5 years ago

So now we need to make it work for themes as well as plugins.

bobbingwide commented 5 years ago

A method called echo() is only supported from PHP 7. After migration oik-plugins.co.uk had reverted to PHP 5.4, so there was a syntax error when echo was encounted as a method name in includes\class-git.php

Workaround: Switch to PHP 7.2... which was what was wanted in the first place.

bobbingwide commented 5 years ago

In oik-plugins.co.uk the plugin called genesis-footer-widgets was uploaded directly from a GIT repository which is not accessible on the Linux server. Checking the plugin produces the following messages.

Remote: \github\bobbingwide\genesis-footer-widgets

Current: error: inflate: data stream error (invalid bit length repeat) fatal: loose object 944bb95b9edaf38cc6e95a81dfd9fd97c9475128 (stored in .git/objects/94/4bb95b9edaf38cc6e95a81dfd9fd97c9475128) is corrupt

Status: error: inflate: data stream error (incorrect data check) fatal: loose object cb5def80b8a4996a2fdb2096b650cbe840532271 (stored in .git/objects/cb/5def80b8a4996a2fdb2096b650cbe840532271) is corrupt
Not safe to pull

Consider adding some logic to deal with problems like this.

bobbingwide commented 5 years ago

We may need to escape the output from the git commands in case there’s HTTP or even JavaScript that could break the display. On core, the diy-oik plugin, the commit SHA was all numeric and got displayed as a telephone number! 1894221

bobbingwide commented 5 years ago

On oik-plugins.com, which didn't have the latest version of oik-batch, I tried ftping the GIT repo from \github\bobbingwide\oik-batch. This enabled oik-batch to work but it could not self check since there were multiple remote repositories and the wrong one was found first. Perhaps it should check for remote called origin to determine the remote address.

bobbingwide commented 4 years ago

In oik-plugins.co.uk I just got the following: 4C8D68B0-BE0E-498B-B48F-88747FFF5CC6

I’ll probably need to add some logic to check if shell_exec() is disabled.