From 2337f8e678b3f0b5b3e1558bca212a736cace4b3 Mon Sep 17 00:00:00 2001 From: Cameron Date: Tue, 11 Jun 2019 10:09:41 -0700 Subject: [PATCH] Support for automated git sync with a theme repo. --- e107_admin/cron.php | 13 +++++++++ e107_handlers/cron_class.php | 33 +++++++++++++++++++++++ e107_handlers/file_class.php | 13 +++++---- e107_languages/English/admin/lan_cron.php | 2 ++ 4 files changed, 56 insertions(+), 5 deletions(-) diff --git a/e107_admin/cron.php b/e107_admin/cron.php index 5b61e19d1..7ff158850 100644 --- a/e107_admin/cron.php +++ b/e107_admin/cron.php @@ -173,6 +173,19 @@ class cron_admin_ui extends e_admin_ui ); } + + + if(is_dir(e_THEME.$pref['sitetheme']."/.git")) + { + $cronDefaults['_system'][8] = array( + 'name' => LAN_CRON_65, + 'category' => 'update', + 'function' => 'gitrepoTheme', + 'description' => LAN_CRON_20_6."
".LAN_WARNING." ".LAN_CRON_20_8, + // 'available' => e107::getPref('ban_retrigger') + ); + + } diff --git a/e107_handlers/cron_class.php b/e107_handlers/cron_class.php index 0d1490f5b..cb8b67587 100644 --- a/e107_handlers/cron_class.php +++ b/e107_handlers/cron_class.php @@ -63,6 +63,39 @@ class _system_cron $fl->chmod(e_BASE."cron.php",0755); $fl->chmod(e_HANDLER."bounce_handler.php",0755); } + + + + + /** + * Update the current Theme Repo + * When using private repos on Github, you'll need to get a personal access token @see https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line + * (with 'repo' access) and then modify the .git/config file : + * @example: + * [remote "origin"] + * url = https://[TOKEN]@github.com/[USER]/[REPO].git + */ + function gitrepoTheme() + { + $mes = e107::getMessage(); + $fl = e107::getFile(); + $theme = e107::getPref('sitetheme'); + + if(is_dir(e_THEME.$theme."/.git")) // Check it's a Git Repo + { + $return = $fl->gitPull($theme, 'theme'); + + $mes->addSuccess($return); + + } + else + { + $mes->addError("No git repo found in theme folder"); //TODO LAN + } + + } + + diff --git a/e107_handlers/file_class.php b/e107_handlers/file_class.php index ab38516ab..1e260a8b5 100644 --- a/e107_handlers/file_class.php +++ b/e107_handlers/file_class.php @@ -1471,17 +1471,20 @@ class e_file $cmd3 = 'cd '.$dir.'; '.$gitPath.' pull'; // Run Pull request - // $mes->addDebug($cmd1); + + $text = ''; + + $mes->addDebug($cmd2); $mes->addDebug($cmd3); - // return false; - // $text = `$cmd1 2>&1`; - $text = `$cmd2 2>&1`; + $text .= `$cmd2 2>&1`; $text .= `$cmd3 2>&1`; - if(deftrue('e_DEBUG')) + + + if(deftrue('e_DEBUG') || deftrue('e_GIT_DEBUG')) { $message = date('r')."\t\tgitPull()\t\t".$text; file_put_contents(e_LOG."fileClass.log",$message,FILE_APPEND); diff --git a/e107_languages/English/admin/lan_cron.php b/e107_languages/English/admin/lan_cron.php index d951880f0..ad2d82b04 100644 --- a/e107_languages/English/admin/lan_cron.php +++ b/e107_languages/English/admin/lan_cron.php @@ -104,3 +104,5 @@ define("LAN_CRON_BACKUP", "Backup"); define("LAN_CRON_LOGGING", "Logging"); define("LAN_CRON_RUNNING", "Running"); +define("LAN_CRON_65", "Update git theme repository"); +