Skip to content

Commit

Permalink
Merge pull request #14177 from eileenmcnaughton/free
Browse files Browse the repository at this point in the history
IDE re-format of tools directory
  • Loading branch information
eileenmcnaughton authored May 4, 2019
2 parents b2e96b9 + b7c0a88 commit ac0451a
Show file tree
Hide file tree
Showing 20 changed files with 344 additions and 285 deletions.
14 changes: 9 additions & 5 deletions tools/bin/scripts/ImportTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
*/



require_once ('bin/cli.php');
require_once('bin/cli.php');
require_once 'CRM/Core/BAO/Tag.php';

/**
Expand All @@ -41,7 +40,7 @@ function __construct() {
die("you need to profide a csv file (1st column parent name, 2nd tag name");
}
$this->file = $this->args[0];
$this->tags = array_flip(CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE)));
$this->tags = array_flip(CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', ['onlyActive' => FALSE]));
}

//format expected: parent name, tag
Expand Down Expand Up @@ -70,12 +69,17 @@ function addTag($param) {
echo "\n- exists already: " . $param['name'];
return;
}
$key = array('tag' => '');
$key = ['tag' => ''];
if ($param['parent']) {
if (array_key_exists($param['parent'], $this->tags)) {
$param['parent_id'] = $this->tags[$param['parent']];
}
else $param['parent_id'] = $this->addTag(array(parent => '', name => $param['parent']));
else {
$param['parent_id'] = $this->addTag([
parent => '',
name => $param['parent'],
]);
}
$tag = CRM_Core_BAO_Tag::add($param, $key);
echo "\n" . $tag->id . ": create " . $param['name'] . " below " . $param['parent'];
}
Expand Down
13 changes: 7 additions & 6 deletions tools/bin/scripts/NormalizePhone.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,20 @@ function run() {

require_once 'Console/Getopt.php';
$shortOptions = "n:p:k:pre";
$longOptions = array('name=', 'pass=', 'key=', 'prefix=');
$longOptions = ['name=', 'pass=', 'key=', 'prefix='];

$getopt = new Console_Getopt();
$args = $getopt->readPHPArgv();

array_shift($args);
list($valid, $dontCare) = $getopt->getopt2($args, $shortOptions, $longOptions);

$vars = array(
$vars = [
'name' => 'n',
'pass' => 'p',
'key' => 'k',
'prefix' => 'pre',
);
];

foreach ($vars as $var => $short) {
$$var = NULL;
Expand Down Expand Up @@ -100,9 +100,10 @@ function processPhones(&$config, $prefix = NULL) {
$dao = &CRM_Core_DAO::executeQuery($query);

$updateQuery = "UPDATE civicrm_phone SET phone = %1 where id = %2";
$params = array(1 => array('', 'String'),
2 => array(0, 'Integer'),
);
$params = [
1 => ['', 'String'],
2 => [0, 'Integer'],
];
$totalPhone = $validPhone = $nonPrefixedPhone = 0;
while ($dao->fetch()) {
$newPhone = processPhone($dao->phone, $prefix);
Expand Down
8 changes: 4 additions & 4 deletions tools/bin/scripts/ckeditorConfigScraper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
* Scrape all config options from the CKEditor documentation site.
*/
$content = file_get_contents('http://docs.ckeditor.com/?print=/api/CKEDITOR.config');
$matches = $output = array();
$matches = $output = [];
preg_match_all("#name expandable'>([^<]+)</a>\s?:\s?(.*)<span.*'short'>([\s\S]*?)</div>#", $content, $matches);
foreach ($matches[1] as $i => $name) {
$output[] = array(
$output[] = [
'id' => $name,
'type' => strip_tags($matches[2][$i]),
'description' => str_replace(array("\n", '. ...'), array(' ', '.'), $matches[3][$i]),
);
'description' => str_replace(["\n", '. ...'], [' ', '.'], $matches[3][$i]),
];
}
if ($output) {
$location = str_replace('tools/bin/scripts', '', __DIR__);
Expand Down
21 changes: 10 additions & 11 deletions tools/bin/scripts/cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@

/**
* A PHP shell script
On drupal if you have a symlink to your civi module, don't forget to create a new file - settings_location.php
Enter the following code (substitute the actual location of your <drupal root>/sites directory)
<?php
define( 'CIVICRM_CONFDIR', '/var/www/drupal.6/sites' );
?>
*
* On drupal if you have a symlink to your civi module, don't forget to create a new file - settings_location.php
* Enter the following code (substitute the actual location of your <drupal root>/sites directory)
* <?php
* define( 'CIVICRM_CONFDIR', '/var/www/drupal.6/sites' );
* ?>
*/
$include_path = "../packages/:" . get_include_path();
set_include_path($include_path);
Expand All @@ -49,19 +48,19 @@ function __construct() {
// set_include_path( $include_path );
require_once 'Console/Getopt.php';
$shortOptions = "s:u:p:k:";
$longOptions = array('site=', 'user', 'pass');
$longOptions = ['site=', 'user', 'pass'];

$getopt = new Console_Getopt();
$args = $getopt->readPHPArgv();
array_shift($args);
list($valid, $this->args) = $getopt->getopt2($args, $shortOptions, $longOptions);

$vars = array(
$vars = [
'user' => 'u',
'pass' => 'p',
'key' => 'k',
'site' => 's',
);
];

foreach ($vars as $var => $short) {
$$var = NULL;
Expand Down Expand Up @@ -102,7 +101,7 @@ function setEnv() {
$_SERVER['PHP_SELF'] = "/index.php";
$_SERVER['HTTP_HOST'] = $this->site;
$_REQUEST['key'] = $this->key;
require_once ("./civicrm.config.php");
require_once("./civicrm.config.php");
}
}

Expand Down
2 changes: 1 addition & 1 deletion tools/bin/scripts/memcache.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
$config = CRM_Core_Config::singleton();
$cache = CRM_Utils_Cache::singleton();

$cache->set('CRM_Core_Config' .CRM_Core_Config::domainID(), $config);
$cache->set('CRM_Core_Config' . CRM_Core_Config::domainID(), $config);
CRM_Core_Error::debug('get', $cache->get('CRM_Core_Config' . CRM_Core_Config::domainID()));

4 changes: 2 additions & 2 deletions tools/bin/scripts/set-version.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
echo "Changing version from $oldVersion to $newVersion...\n";

$verName = makeVerName($newVersion);
$phpFile = initFile("CRM/Upgrade/Incremental/php/{$verName}.php", function() use ($verName) {
$phpFile = initFile("CRM/Upgrade/Incremental/php/{$verName}.php", function () use ($verName) {
ob_start();
global $camelNumber;
$camelNumber = $verName;
Expand All @@ -53,7 +53,7 @@
return ob_get_clean();
});

$sqlFile = initFile("CRM/Upgrade/Incremental/sql/{$newVersion}.mysql.tpl", function() use ($newVersion) {
$sqlFile = initFile("CRM/Upgrade/Incremental/sql/{$newVersion}.mysql.tpl", function () use ($newVersion) {
return "{* file to handle db changes in $newVersion during upgrade *}\n";
});

Expand Down
8 changes: 5 additions & 3 deletions tools/bin/scripts/testProcess.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
require_once '../civicrm.config.php'; require_once 'CRM/Core/Config.php';
require_once '../civicrm.config.php';
require_once 'CRM/Core/Config.php';
require_once 'CRM/Core/Error.php';
$config = CRM_Core_Config::singleton();

Expand All @@ -10,13 +11,14 @@
exit();

$xmlProcessor->run(104, 1, 'Substance Abuse', '15 Day Review');
$params = array('clientID' => 104,
$params = [
'clientID' => 104,
'creatorID' => 108,
'standardTimeline' => 1,
'activityTypeName' => 'Open Case',
'dueDateTime' => time(),
'caseID' => 1,
);
];
require_once 'CRM/Case/XMLProcessor/Process.php';
$xmlProcessor = new CRM_Case_XMLProcessor_Process();

Expand Down
12 changes: 6 additions & 6 deletions tools/bin/scripts/updateNameCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
*/



/*
* This script recaches the display_name and sort_name values
*
Expand All @@ -42,7 +41,7 @@ class CRM_UpdateNameCache {
function __construct() {
// you can run this program either from an apache command, or from the cli
if (php_sapi_name() == "cli") {
require_once ("cli.php");
require_once("cli.php");
$cli = new civicrm_cli();
//if it doesn't die, it's authenticated
}
Expand Down Expand Up @@ -81,9 +80,9 @@ public function updateConstructedNames() {
$prefixes = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'prefix_id');
$suffixes = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'suffix_id');

$tokens = array();
$tokens = [];
CRM_Utils_Hook::tokens($tokens);
$tokenFields = array();
$tokenFields = [];
foreach ($tokens as $category => $catTokens) {
foreach ($catTokens as $token) {
$tokenFields[] = $token;
Expand All @@ -100,12 +99,13 @@ public function updateConstructedNames() {

while ($dao->fetch()) {
$contactID = $dao->id;
$params = array('first_name' => $dao->first_name,
$params = [
'first_name' => $dao->first_name,
'middle_name' => $dao->middle_name,
'last_name' => $dao->last_name,
'prefix_id' => $dao->prefix_id,
'suffix_id' => $dao->suffix_id,
);
];
$params['individual_prefix'] = $prefixes[$dao->prefix_id];
$params['individual_suffix'] = $suffixes[$dao->suffix_id];

Expand Down
Loading

0 comments on commit ac0451a

Please sign in to comment.