First commit
This commit is contained in:
commit
c6e2478c40
13918 changed files with 2303184 additions and 0 deletions
502
sites/all/modules/civicrm/bin/ContributionProcessor.php
Normal file
502
sites/all/modules/civicrm/bin/ContributionProcessor.php
Normal file
|
@ -0,0 +1,502 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
class CiviContributeProcessor {
|
||||
static $_paypalParamsMapper = array(
|
||||
//category => array(paypal_param => civicrm_field);
|
||||
'contact' => array(
|
||||
'salutation' => 'prefix_id',
|
||||
'firstname' => 'first_name',
|
||||
'lastname' => 'last_name',
|
||||
'middlename' => 'middle_name',
|
||||
'suffix' => 'suffix_id',
|
||||
'email' => 'email',
|
||||
),
|
||||
'location' => array(
|
||||
'shiptoname' => 'address_name',
|
||||
'shiptostreet' => 'street_address',
|
||||
'shiptostreet2' => 'supplemental_address_1',
|
||||
'shiptocity' => 'city',
|
||||
'shiptostate' => 'state_province',
|
||||
'shiptozip' => 'postal_code',
|
||||
'countrycode' => 'country',
|
||||
),
|
||||
'transaction' => array(
|
||||
'amt' => 'total_amount',
|
||||
'feeamt' => 'fee_amount',
|
||||
'transactionid' => 'trxn_id',
|
||||
'currencycode' => 'currency',
|
||||
'l_name0' => 'source',
|
||||
'ordertime' => 'receive_date',
|
||||
'note' => 'note',
|
||||
'custom' => 'note',
|
||||
'l_number0' => 'note',
|
||||
'is_test' => 'is_test',
|
||||
'transactiontype' => 'trxn_type',
|
||||
'recurrences' => 'installments',
|
||||
'l_amt2' => 'amount',
|
||||
'l_period2' => 'lol',
|
||||
'invnum' => 'invoice_id',
|
||||
'subscriptiondate' => 'start_date',
|
||||
'subscriptionid' => 'processor_id',
|
||||
'timestamp' => 'modified_date',
|
||||
),
|
||||
);
|
||||
|
||||
static $_csvParamsMapper = array(
|
||||
// Note: if csv header is not present in the mapper, header itself
|
||||
// is considered as a civicrm field.
|
||||
//category => array(csv_header => civicrm_field);
|
||||
'contact' => array(
|
||||
'first_name' => 'first_name',
|
||||
'last_name' => 'last_name',
|
||||
'middle_name' => 'middle_name',
|
||||
'email' => 'email',
|
||||
),
|
||||
'location' => array(
|
||||
'street_address' => 'street_address',
|
||||
'supplemental_address_1' => 'supplemental_address_1',
|
||||
'city' => 'city',
|
||||
'postal_code' => 'postal_code',
|
||||
'country' => 'country',
|
||||
),
|
||||
'transaction' => array(
|
||||
'total_amount' => 'total_amount',
|
||||
'trxn_id' => 'trxn_id',
|
||||
'currency' => 'currency',
|
||||
'source' => 'source',
|
||||
'receive_date' => 'receive_date',
|
||||
'note' => 'note',
|
||||
'is_test' => 'is_test',
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* @param $paymentProcessor
|
||||
* @param $paymentMode
|
||||
* @param $start
|
||||
* @param $end
|
||||
*/
|
||||
public static function paypal($paymentProcessor, $paymentMode, $start, $end) {
|
||||
$url = "{$paymentProcessor['url_api']}nvp";
|
||||
|
||||
$keyArgs = array(
|
||||
'user' => $paymentProcessor['user_name'],
|
||||
'pwd' => $paymentProcessor['password'],
|
||||
'signature' => $paymentProcessor['signature'],
|
||||
'version' => 3.0,
|
||||
);
|
||||
|
||||
$args = $keyArgs;
|
||||
$args += array(
|
||||
'method' => 'TransactionSearch',
|
||||
'startdate' => $start,
|
||||
'enddate' => $end,
|
||||
);
|
||||
|
||||
require_once 'CRM/Core/Payment/PayPalImpl.php';
|
||||
|
||||
// as invokeAPI fetch only last 100 transactions.
|
||||
// we should require recursive calls to process more than 100.
|
||||
// first fetch transactions w/ give date intervals.
|
||||
// if we get error code w/ result, which means we do have more than 100
|
||||
// manipulate date interval accordingly and fetch again.
|
||||
|
||||
do {
|
||||
$result = CRM_Core_Payment_PayPalImpl::invokeAPI($args, $url);
|
||||
require_once "CRM/Contribute/BAO/Contribution/Utils.php";
|
||||
|
||||
$keyArgs['method'] = 'GetTransactionDetails';
|
||||
foreach ($result as $name => $value) {
|
||||
if (substr($name, 0, 15) == 'l_transactionid') {
|
||||
|
||||
// We don't/can't process subscription notifications, which appear
|
||||
// to be identified by transaction ids beginning with S-
|
||||
if (substr($value, 0, 2) == 'S-') {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Before we bother making a remote API call to PayPal to lookup
|
||||
// details about a transaction, let's make sure that it doesn't
|
||||
// already exist in the database.
|
||||
require_once 'CRM/Contribute/DAO/Contribution.php';
|
||||
$dao = new CRM_Contribute_DAO_Contribution();
|
||||
$dao->trxn_id = $value;
|
||||
if ($dao->find(TRUE)) {
|
||||
preg_match('/(\d+)$/', $name, $matches);
|
||||
$seq = $matches[1];
|
||||
$email = $result["l_email{$seq}"];
|
||||
$amt = $result["l_amt{$seq}"];
|
||||
CRM_Core_Error::debug_log_message("Skipped (already recorded) - $email, $amt, $value ..<p>", TRUE);
|
||||
continue;
|
||||
}
|
||||
|
||||
$keyArgs['transactionid'] = $value;
|
||||
$trxnDetails = CRM_Core_Payment_PayPalImpl::invokeAPI($keyArgs, $url);
|
||||
if (is_a($trxnDetails, 'CRM_Core_Error')) {
|
||||
echo "PAYPAL ERROR: Skipping transaction id: $value<p>";
|
||||
continue;
|
||||
}
|
||||
|
||||
// only process completed payments
|
||||
if (strtolower($trxnDetails['paymentstatus']) != 'completed') {
|
||||
continue;
|
||||
}
|
||||
|
||||
// only process receipts, not payments
|
||||
if (strtolower($trxnDetails['transactiontype']) == 'sendmoney') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$params = self::formatAPIParams($trxnDetails,
|
||||
self::$_paypalParamsMapper,
|
||||
'paypal'
|
||||
);
|
||||
if ($paymentMode == 'test') {
|
||||
$params['transaction']['is_test'] = 1;
|
||||
}
|
||||
else {
|
||||
$params['transaction']['is_test'] = 0;
|
||||
}
|
||||
|
||||
try {
|
||||
if (self::processAPIContribution($params)) {
|
||||
CRM_Core_Error::debug_log_message("Processed - {$trxnDetails['email']}, {$trxnDetails['amt']}, {$value} ..<p>", TRUE);
|
||||
}
|
||||
else {
|
||||
CRM_Core_Error::debug_log_message("Skipped - {$trxnDetails['email']}, {$trxnDetails['amt']}, {$value} ..<p>", TRUE);
|
||||
}
|
||||
}
|
||||
catch (CiviCRM_API3_Exception $e) {
|
||||
CRM_Core_Error::debug_log_message("Skipped - {$trxnDetails['email']}, {$trxnDetails['amt']}, {$value} ..<p>", TRUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($result['l_errorcode0'] == '11002') {
|
||||
$end = $result['l_timestamp99'];
|
||||
$end_time = strtotime("{$end}", time());
|
||||
$end_date = date('Y-m-d\T00:00:00.00\Z', $end_time);
|
||||
$args['enddate'] = $end_date;
|
||||
}
|
||||
} while ($result['l_errorcode0'] == '11002');
|
||||
}
|
||||
|
||||
public static function csv() {
|
||||
$csvFile = '/home/deepak/Desktop/crm-4247.csv';
|
||||
$delimiter = ";";
|
||||
$row = 1;
|
||||
|
||||
$handle = fopen($csvFile, "r");
|
||||
if (!$handle) {
|
||||
CRM_Core_Error::fatal("Can't locate csv file.");
|
||||
}
|
||||
|
||||
require_once "CRM/Contribute/BAO/Contribution/Utils.php";
|
||||
while (($data = fgetcsv($handle, 1000, $delimiter)) !== FALSE) {
|
||||
if ($row !== 1) {
|
||||
$data['header'] = $header;
|
||||
$params = self::formatAPIParams($data,
|
||||
self::$_csvParamsMapper,
|
||||
'csv'
|
||||
);
|
||||
if (self::processAPIContribution($params)) {
|
||||
CRM_Core_Error::debug_log_message("Processed - line $row of csv file .. {$params['email']}, {$params['transaction']['total_amount']}, {$params['transaction']['trxn_id']} ..<p>", TRUE);
|
||||
}
|
||||
else {
|
||||
CRM_Core_Error::debug_log_message("Skipped - line $row of csv file .. {$params['email']}, {$params['transaction']['total_amount']}, {$params['transaction']['trxn_id']} ..<p>", TRUE);
|
||||
}
|
||||
|
||||
// clean up memory from dao's
|
||||
CRM_Core_DAO::freeResult();
|
||||
}
|
||||
else {
|
||||
// we assuming - first row is always the header line
|
||||
$header = $data;
|
||||
CRM_Core_Error::debug_log_message("Considering first row ( line $row ) as HEADER ..<p>", TRUE);
|
||||
|
||||
if (empty($header)) {
|
||||
CRM_Core_Error::fatal("Header is empty.");
|
||||
}
|
||||
}
|
||||
$row++;
|
||||
}
|
||||
fclose($handle);
|
||||
}
|
||||
|
||||
public static function process() {
|
||||
require_once 'CRM/Utils/Request.php';
|
||||
|
||||
$type = CRM_Utils_Request::retrieve('type', 'String', CRM_Core_DAO::$_nullObject, FALSE, 'csv', 'REQUEST');
|
||||
$type = strtolower($type);
|
||||
|
||||
switch ($type) {
|
||||
case 'paypal':
|
||||
$start = CRM_Utils_Request::retrieve('start', 'String',
|
||||
CRM_Core_DAO::$_nullObject, FALSE, 31, 'REQUEST'
|
||||
);
|
||||
$end = CRM_Utils_Request::retrieve('end', 'String',
|
||||
CRM_Core_DAO::$_nullObject, FALSE, 0, 'REQUEST'
|
||||
);
|
||||
if ($start < $end) {
|
||||
CRM_Core_Error::fatal("Start offset can't be less than End offset.");
|
||||
}
|
||||
|
||||
$start = date('Y-m-d', time() - $start * 24 * 60 * 60) . 'T00:00:00.00Z';
|
||||
$end = date('Y-m-d', time() - $end * 24 * 60 * 60) . 'T23:59:00.00Z';
|
||||
|
||||
$ppID = CRM_Utils_Request::retrieve('ppID', 'Integer',
|
||||
CRM_Core_DAO::$_nullObject, TRUE, NULL, 'REQUEST'
|
||||
);
|
||||
$mode = CRM_Utils_Request::retrieve('ppMode', 'String',
|
||||
CRM_Core_DAO::$_nullObject, FALSE, 'live', 'REQUEST'
|
||||
);
|
||||
|
||||
$paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($ppID, $mode);
|
||||
|
||||
CRM_Core_Error::debug_log_message("Start Date=$start, End Date=$end, ppID=$ppID, mode=$mode <p>", TRUE);
|
||||
|
||||
return self::$type($paymentProcessor, $mode, $start, $end);
|
||||
|
||||
case 'csv':
|
||||
return self::csv();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $apiParams
|
||||
* @param $mapper
|
||||
* @param string $type
|
||||
* @param bool $category
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function formatAPIParams($apiParams, $mapper, $type = 'paypal', $category = TRUE) {
|
||||
$type = strtolower($type);
|
||||
|
||||
if (!in_array($type, array(
|
||||
'paypal',
|
||||
'csv',
|
||||
))
|
||||
) {
|
||||
// return the params as is
|
||||
return $apiParams;
|
||||
}
|
||||
$params = $transaction = array();
|
||||
|
||||
if ($type == 'paypal') {
|
||||
foreach ($apiParams as $detail => $val) {
|
||||
if (isset($mapper['contact'][$detail])) {
|
||||
$params[$mapper['contact'][$detail]] = $val;
|
||||
}
|
||||
elseif (isset($mapper['location'][$detail])) {
|
||||
$params['address'][1][$mapper['location'][$detail]] = $val;
|
||||
}
|
||||
elseif (isset($mapper['transaction'][$detail])) {
|
||||
switch ($detail) {
|
||||
case 'l_period2':
|
||||
// Sadly, PayPal seems to send two distinct data elements in a single field,
|
||||
// so we break them out here. This is somewhat ugly and tragic.
|
||||
$freqUnits = array(
|
||||
'D' => 'day',
|
||||
'W' => 'week',
|
||||
'M' => 'month',
|
||||
'Y' => 'year',
|
||||
);
|
||||
list($frequency_interval, $frequency_unit) = explode(' ', $val);
|
||||
$transaction['frequency_interval'] = $frequency_interval;
|
||||
$transaction['frequency_unit'] = $freqUnits[$frequency_unit];
|
||||
break;
|
||||
|
||||
case 'subscriptiondate':
|
||||
case 'timestamp':
|
||||
// PayPal dates are in ISO-8601 format. We need a format that
|
||||
// MySQL likes
|
||||
$unix_timestamp = strtotime($val);
|
||||
$transaction[$mapper['transaction'][$detail]] = date('YmdHis', $unix_timestamp);
|
||||
break;
|
||||
|
||||
case 'note':
|
||||
case 'custom':
|
||||
case 'l_number0':
|
||||
if ($val) {
|
||||
$val = "[PayPal_field:{$detail}] {$val}";
|
||||
$transaction[$mapper['transaction'][$detail]] = !empty($transaction[$mapper['transaction'][$detail]]) ? $transaction[$mapper['transaction'][$detail]] . " <br/> " . $val : $val;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
$transaction[$mapper['transaction'][$detail]] = $val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($transaction) && $category) {
|
||||
$params['transaction'] = $transaction;
|
||||
}
|
||||
else {
|
||||
$params += $transaction;
|
||||
}
|
||||
|
||||
CRM_Contribute_BAO_Contribution_Utils::_fillCommonParams($params, $type);
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
if ($type == 'csv') {
|
||||
$header = $apiParams['header'];
|
||||
unset($apiParams['header']);
|
||||
foreach ($apiParams as $key => $val) {
|
||||
if (isset($mapper['contact'][$header[$key]])) {
|
||||
$params[$mapper['contact'][$header[$key]]] = $val;
|
||||
}
|
||||
elseif (isset($mapper['location'][$header[$key]])) {
|
||||
$params['address'][1][$mapper['location'][$header[$key]]] = $val;
|
||||
}
|
||||
elseif (isset($mapper['transaction'][$header[$key]])) {
|
||||
$transaction[$mapper['transaction'][$header[$key]]] = $val;
|
||||
}
|
||||
else {
|
||||
$params[$header[$key]] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($transaction) && $category) {
|
||||
$params['transaction'] = $transaction;
|
||||
}
|
||||
else {
|
||||
$params += $transaction;
|
||||
}
|
||||
|
||||
CRM_Contribute_BAO_Contribution_Utils::_fillCommonParams($params, $type);
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated function.
|
||||
*
|
||||
* This function has probably been defunct for quite a long time.
|
||||
*
|
||||
* @param array $params
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function processAPIContribution($params) {
|
||||
if (empty($params) || array_key_exists('error', $params)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$params['contact_id'] = CRM_Contact_BAO_Contact::getFirstDuplicateContact($params, 'Individual', 'Unsupervised', array(), FALSE);
|
||||
|
||||
$contact = civicrm_api3('Contact', 'create', $params);
|
||||
|
||||
// only pass transaction params to contribution::create, if available
|
||||
if (array_key_exists('transaction', $params)) {
|
||||
$params = $params['transaction'];
|
||||
$params['contact_id'] = $contact['id'];
|
||||
}
|
||||
|
||||
$params['custom'] = CRM_Core_BAO_CustomField::postProcess($params,
|
||||
CRM_Utils_Array::value('id', $params, NULL),
|
||||
'Contribution'
|
||||
);
|
||||
// create contribution
|
||||
|
||||
// if this is a recurring contribution then process it first
|
||||
if ($params['trxn_type'] == 'subscrpayment') {
|
||||
// see if a recurring record already exists
|
||||
$recurring = new CRM_Contribute_BAO_ContributionRecur();
|
||||
$recurring->processor_id = $params['processor_id'];
|
||||
if (!$recurring->find(TRUE)) {
|
||||
$recurring = new CRM_Contribute_BAO_ContributionRecur();
|
||||
$recurring->invoice_id = $params['invoice_id'];
|
||||
$recurring->find(TRUE);
|
||||
}
|
||||
|
||||
// This is the same thing the CiviCRM IPN handler does to handle
|
||||
// subsequent recurring payments to avoid duplicate contribution
|
||||
// errors due to invoice ID. See:
|
||||
// ./CRM/Core/Payment/PayPalIPN.php:200
|
||||
if ($recurring->id) {
|
||||
$params['invoice_id'] = md5(uniqid(rand(), TRUE));
|
||||
}
|
||||
|
||||
$recurring->copyValues($params);
|
||||
$recurring->save();
|
||||
if (is_a($recurring, 'CRM_Core_Error')) {
|
||||
return FALSE;
|
||||
}
|
||||
else {
|
||||
$params['contribution_recur_id'] = $recurring->id;
|
||||
}
|
||||
}
|
||||
|
||||
$contribution = CRM_Contribute_BAO_Contribution::create($params);
|
||||
if (!$contribution->id) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// bootstrap the environment and run the processor
|
||||
session_start();
|
||||
require_once '../civicrm.config.php';
|
||||
require_once 'CRM/Core/Config.php';
|
||||
$config = CRM_Core_Config::singleton();
|
||||
|
||||
CRM_Utils_System::authenticateScript(TRUE);
|
||||
|
||||
//log the execution of script
|
||||
CRM_Core_Error::debug_log_message('ContributionProcessor.php');
|
||||
|
||||
$lock = Civi::lockManager()->acquire('worker.contribute.CiviContributeProcessor');
|
||||
|
||||
if ($lock->isAcquired()) {
|
||||
// try to unset any time limits
|
||||
if (!ini_get('safe_mode')) {
|
||||
set_time_limit(0);
|
||||
}
|
||||
|
||||
CiviContributeProcessor::process();
|
||||
}
|
||||
else {
|
||||
throw new Exception('Could not acquire lock, another CiviContributeProcessor process is running');
|
||||
}
|
||||
|
||||
$lock->release();
|
||||
|
||||
echo "Done processing<p>";
|
505
sites/all/modules/civicrm/bin/cli.class.php
Normal file
505
sites/all/modules/civicrm/bin/cli.class.php
Normal file
|
@ -0,0 +1,505 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright Tech To The People http:tttp.eu (c) 2008 |
|
||||
+--------------------------------------------------------------------+
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
* This files provides several classes for doing command line work with
|
||||
* CiviCRM. civicrm_cli is the base class. It's used by cli.php.
|
||||
*
|
||||
* In addition, there are several additional classes that inherit
|
||||
* civicrm_cli to do more precise functions.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* base class for doing all command line operations via civicrm
|
||||
* used by cli.php
|
||||
*/
|
||||
class civicrm_cli {
|
||||
// required values that must be passed
|
||||
// via the command line
|
||||
var $_required_arguments = array('action', 'entity');
|
||||
var $_additional_arguments = array();
|
||||
var $_entity = NULL;
|
||||
var $_action = NULL;
|
||||
var $_output = FALSE;
|
||||
var $_joblog = FALSE;
|
||||
var $_semicolon = FALSE;
|
||||
var $_config;
|
||||
|
||||
// optional arguments
|
||||
var $_site = 'localhost';
|
||||
var $_user = NULL;
|
||||
var $_password = NULL;
|
||||
|
||||
// all other arguments populate the parameters
|
||||
// array that is passed to civicrm_api
|
||||
var $_params = array('version' => 3);
|
||||
|
||||
var $_errors = array();
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function initialize() {
|
||||
if (!$this->_accessing_from_cli()) {
|
||||
return FALSE;
|
||||
}
|
||||
if (!$this->_parseOptions()) {
|
||||
return FALSE;
|
||||
}
|
||||
if (!$this->_bootstrap()) {
|
||||
return FALSE;
|
||||
}
|
||||
if (!$this->_validateOptions()) {
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure function is being run from the cli.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function _accessing_from_cli() {
|
||||
if (PHP_SAPI === 'cli') {
|
||||
return TRUE;
|
||||
}
|
||||
else {
|
||||
die("cli.php can only be run from command line.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function callApi() {
|
||||
require_once 'api/api.php';
|
||||
|
||||
CRM_Core_Config::setPermitCacheFlushMode(FALSE);
|
||||
// CRM-9822 -'execute' action always goes thru Job api and always writes to log
|
||||
if ($this->_action != 'execute' && $this->_joblog) {
|
||||
require_once 'CRM/Core/JobManager.php';
|
||||
$facility = new CRM_Core_JobManager();
|
||||
$facility->setSingleRunParams($this->_entity, $this->_action, $this->_params, 'From Cli.php');
|
||||
$facility->executeJobByAction($this->_entity, $this->_action);
|
||||
}
|
||||
else {
|
||||
// CRM-9822 cli.php calls don't require site-key, so bypass site-key authentication
|
||||
$this->_params['auth'] = FALSE;
|
||||
$result = civicrm_api($this->_entity, $this->_action, $this->_params);
|
||||
}
|
||||
CRM_Core_Config::setPermitCacheFlushMode(TRUE);
|
||||
CRM_Contact_BAO_Contact_Utils::clearContactCaches();
|
||||
|
||||
if (!empty($result['is_error'])) {
|
||||
$this->_log($result['error_message']);
|
||||
return FALSE;
|
||||
}
|
||||
elseif ($this->_output === 'json') {
|
||||
echo json_encode($result, defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0);
|
||||
}
|
||||
elseif ($this->_output) {
|
||||
print_r($result['values']);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
private function _parseOptions() {
|
||||
$args = $_SERVER['argv'];
|
||||
// remove the first argument, which is the name
|
||||
// of this script
|
||||
array_shift($args);
|
||||
|
||||
while (list($k, $arg) = each($args)) {
|
||||
// sanitize all user input
|
||||
$arg = $this->_sanitize($arg);
|
||||
|
||||
// if we're not parsing an option signifier
|
||||
// continue to the next one
|
||||
if (!preg_match('/^-/', $arg)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// find the value of this arg
|
||||
if (preg_match('/=/', $arg)) {
|
||||
$parts = explode('=', $arg);
|
||||
$arg = $parts[0];
|
||||
$value = $parts[1];
|
||||
}
|
||||
else {
|
||||
if (isset($args[$k + 1])) {
|
||||
$next_arg = $this->_sanitize($args[$k + 1]);
|
||||
// if the next argument is not another option
|
||||
// it's the value for this argument
|
||||
if (!preg_match('/^-/', $next_arg)) {
|
||||
$value = $next_arg;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// parse the special args first
|
||||
if ($arg == '-e' || $arg == '--entity') {
|
||||
$this->_entity = $value;
|
||||
}
|
||||
elseif ($arg == '-a' || $arg == '--action') {
|
||||
$this->_action = $value;
|
||||
}
|
||||
elseif ($arg == '-s' || $arg == '--site') {
|
||||
$this->_site = $value;
|
||||
}
|
||||
elseif ($arg == '-u' || $arg == '--user') {
|
||||
$this->_user = $value;
|
||||
}
|
||||
elseif ($arg == '-p' || $arg == '--password') {
|
||||
$this->_password = $value;
|
||||
}
|
||||
elseif ($arg == '-o' || $arg == '--output') {
|
||||
$this->_output = TRUE;
|
||||
}
|
||||
elseif ($arg == '-J' || $arg == '--json') {
|
||||
$this->_output = 'json';
|
||||
}
|
||||
elseif ($arg == '-j' || $arg == '--joblog') {
|
||||
$this->_joblog = TRUE;
|
||||
}
|
||||
elseif ($arg == '-sem' || $arg == '--semicolon') {
|
||||
$this->_semicolon = TRUE;
|
||||
}
|
||||
else {
|
||||
foreach ($this->_additional_arguments as $short => $long) {
|
||||
if ($arg == '-' . $short || $arg == '--' . $long) {
|
||||
$property = '_' . $long;
|
||||
$this->$property = $value;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// all other arguments are parameters
|
||||
$key = ltrim($arg, '--');
|
||||
$this->_params[$key] = isset($value) ? $value : NULL;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
private function _bootstrap() {
|
||||
// so the configuration works with php-cli
|
||||
$_SERVER['PHP_SELF'] = "/index.php";
|
||||
$_SERVER['HTTP_HOST'] = $this->_site;
|
||||
$_SERVER['REMOTE_ADDR'] = "127.0.0.1";
|
||||
$_SERVER['SERVER_SOFTWARE'] = NULL;
|
||||
$_SERVER['REQUEST_METHOD'] = 'GET';
|
||||
|
||||
// SCRIPT_FILENAME needed by CRM_Utils_System::cmsRootPath
|
||||
$_SERVER['SCRIPT_FILENAME'] = __FILE__;
|
||||
|
||||
// CRM-8917 - check if script name starts with /, if not - prepend it.
|
||||
if (ord($_SERVER['SCRIPT_NAME']) != 47) {
|
||||
$_SERVER['SCRIPT_NAME'] = '/' . $_SERVER['SCRIPT_NAME'];
|
||||
}
|
||||
|
||||
$civicrm_root = dirname(__DIR__);
|
||||
chdir($civicrm_root);
|
||||
if (getenv('CIVICRM_SETTINGS')) {
|
||||
require_once getenv('CIVICRM_SETTINGS');
|
||||
}
|
||||
else {
|
||||
require_once 'civicrm.config.php';
|
||||
}
|
||||
// autoload
|
||||
if (!class_exists('CRM_Core_ClassLoader')) {
|
||||
require_once $civicrm_root . '/CRM/Core/ClassLoader.php';
|
||||
}
|
||||
CRM_Core_ClassLoader::singleton()->register();
|
||||
|
||||
$this->_config = CRM_Core_Config::singleton();
|
||||
|
||||
// HTTP_HOST will be 'localhost' unless overwritten with the -s argument.
|
||||
// Now we have a Config object, we can set it from the Base URL.
|
||||
if ($_SERVER['HTTP_HOST'] == 'localhost') {
|
||||
$_SERVER['HTTP_HOST'] = preg_replace(
|
||||
'!^https?://([^/]+)/$!i',
|
||||
'$1',
|
||||
$this->_config->userFrameworkBaseURL);
|
||||
}
|
||||
|
||||
$class = 'CRM_Utils_System_' . $this->_config->userFramework;
|
||||
|
||||
$cms = new $class();
|
||||
if (!CRM_Utils_System::loadBootstrap(array(), FALSE, FALSE, $civicrm_root)) {
|
||||
$this->_log(ts("Failed to bootstrap CMS"));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (strtolower($this->_entity) == 'job') {
|
||||
if (!$this->_user) {
|
||||
$this->_log(ts("Jobs called from cli.php require valid user as parameter"));
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($this->_user)) {
|
||||
if (!CRM_Utils_System::authenticateScript(TRUE, $this->_user, $this->_password, TRUE, FALSE, FALSE)) {
|
||||
$this->_log(ts("Failed to login as %1. Wrong username or password.", array('1' => $this->_user)));
|
||||
return FALSE;
|
||||
}
|
||||
if (($this->_config->userFramework == 'Joomla' && !$cms->loadUser($this->_user, $this->_password)) || !$cms->loadUser($this->_user)) {
|
||||
$this->_log(ts("Failed to login as %1", array('1' => $this->_user)));
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
private function _validateOptions() {
|
||||
$required = $this->_required_arguments;
|
||||
while (list(, $var) = each($required)) {
|
||||
$index = '_' . $var;
|
||||
if (empty($this->$index)) {
|
||||
$missing_arg = '--' . $var;
|
||||
$this->_log(ts("The %1 argument is required", array(1 => $missing_arg)));
|
||||
$this->_log($this->_getUsage());
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function _sanitize($value) {
|
||||
// restrict user input - we should not be needing anything
|
||||
// other than normal alpha numeric plus - and _.
|
||||
return trim(preg_replace('#^[^a-zA-Z0-9\-_=/]$#', '', $value));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function _getUsage() {
|
||||
$out = "Usage: cli.php -e entity -a action [-u user] [-s site] [--output|--json] [PARAMS]\n";
|
||||
$out .= " entity is the name of the entity, e.g. Contact, Event, etc.\n";
|
||||
$out .= " action is the name of the action e.g. Get, Create, etc.\n";
|
||||
$out .= " user is an optional username to run the script as\n";
|
||||
$out .= " site is the domain name of the web site (for Drupal multi site installs)\n";
|
||||
$out .= " --output will pretty print the result from the api call\n";
|
||||
$out .= " --json will print the result from the api call as JSON\n";
|
||||
$out .= " PARAMS is one or more --param=value combinations to pass to the api\n";
|
||||
return ts($out);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $error
|
||||
*/
|
||||
private function _log($error) {
|
||||
// fixme, this should call some CRM_Core_Error:: function
|
||||
// that properly logs
|
||||
print "$error\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* class used by csv/export.php to export records from
|
||||
* the database in a csv file format.
|
||||
*/
|
||||
class civicrm_cli_csv_exporter extends civicrm_cli {
|
||||
var $separator = ',';
|
||||
|
||||
/**
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->_required_arguments = array('entity');
|
||||
parent::initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the script.
|
||||
*/
|
||||
public function run() {
|
||||
if ($this->_semicolon) {
|
||||
$this->separator = ';';
|
||||
}
|
||||
|
||||
$out = fopen("php://output", 'w');
|
||||
fputcsv($out, $this->columns, $this->separator, '"');
|
||||
|
||||
$this->row = 1;
|
||||
$result = civicrm_api($this->_entity, 'Get', $this->_params);
|
||||
$first = TRUE;
|
||||
foreach ($result['values'] as $row) {
|
||||
if ($first) {
|
||||
$columns = array_keys($row);
|
||||
fputcsv($out, $columns, $this->separator, '"');
|
||||
$first = FALSE;
|
||||
}
|
||||
//handle values returned as arrays (i.e. custom fields that allow multiple selections) by inserting a control character
|
||||
foreach ($row as &$field) {
|
||||
if (is_array($field)) {
|
||||
//convert to string
|
||||
$field = implode($field, CRM_Core_DAO::VALUE_SEPARATOR) . CRM_Core_DAO::VALUE_SEPARATOR;
|
||||
}
|
||||
}
|
||||
fputcsv($out, $row, $this->separator, '"');
|
||||
}
|
||||
fclose($out);
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* base class used by both civicrm_cli_csv_import
|
||||
* and civicrm_cli_csv_deleter to add or delete
|
||||
* records based on those found in a csv file
|
||||
* passed to the script.
|
||||
*/
|
||||
class civicrm_cli_csv_file extends civicrm_cli {
|
||||
var $header;
|
||||
var $separator = ',';
|
||||
|
||||
/**
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->_required_arguments = array('entity', 'file');
|
||||
$this->_additional_arguments = array('f' => 'file');
|
||||
parent::initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Run CLI function.
|
||||
*/
|
||||
public function run() {
|
||||
$this->row = 1;
|
||||
$handle = fopen($this->_file, "r");
|
||||
|
||||
if (!$handle) {
|
||||
die("Could not open file: " . $this->_file . ". Please provide an absolute path.\n");
|
||||
}
|
||||
|
||||
//header
|
||||
$header = fgetcsv($handle, 0, $this->separator);
|
||||
// In case fgetcsv couldn't parse the header and dumped the whole line in 1 array element
|
||||
// Try a different separator char
|
||||
if (count($header) == 1) {
|
||||
$this->separator = ";";
|
||||
rewind($handle);
|
||||
$header = fgetcsv($handle, 0, $this->separator);
|
||||
}
|
||||
|
||||
$this->header = $header;
|
||||
while (($data = fgetcsv($handle, 0, $this->separator)) !== FALSE) {
|
||||
// skip blank lines
|
||||
if (count($data) == 1 && is_null($data[0])) {
|
||||
continue;
|
||||
}
|
||||
$this->row++;
|
||||
if ($this->row % 1000 == 0) {
|
||||
// Reset PEAR_DB_DATAOBJECT cache to prevent memory leak
|
||||
CRM_Core_DAO::freeResult();
|
||||
}
|
||||
$params = $this->convertLine($data);
|
||||
$this->processLine($params);
|
||||
}
|
||||
fclose($handle);
|
||||
}
|
||||
|
||||
/* return a params as expected */
|
||||
/**
|
||||
* @param $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function convertLine($data) {
|
||||
$params = array();
|
||||
foreach ($this->header as $i => $field) {
|
||||
//split any multiselect data, denoted with CRM_Core_DAO::VALUE_SEPARATOR
|
||||
if (strpos($data[$i], CRM_Core_DAO::VALUE_SEPARATOR) !== FALSE) {
|
||||
$data[$i] = explode(CRM_Core_DAO::VALUE_SEPARATOR, $data[$i]);
|
||||
$data[$i] = array_combine($data[$i], $data[$i]);
|
||||
}
|
||||
$params[$field] = $data[$i];
|
||||
}
|
||||
$params['version'] = 3;
|
||||
return $params;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* class for processing records to add
|
||||
* used by csv/import.php
|
||||
*
|
||||
*/
|
||||
class civicrm_cli_csv_importer extends civicrm_cli_csv_file {
|
||||
/**
|
||||
* @param array $params
|
||||
*/
|
||||
public function processline($params) {
|
||||
$result = civicrm_api($this->_entity, 'Create', $params);
|
||||
if ($result['is_error']) {
|
||||
echo "\nERROR line " . $this->row . ": " . $result['error_message'] . "\n";
|
||||
}
|
||||
else {
|
||||
echo "\nline " . $this->row . ": created " . $this->_entity . " id: " . $result['id'] . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* class for processing records to delete
|
||||
* used by csv/delete.php
|
||||
*
|
||||
*/
|
||||
class civicrm_cli_csv_deleter extends civicrm_cli_csv_file {
|
||||
/**
|
||||
* @param array $params
|
||||
*/
|
||||
public function processline($params) {
|
||||
$result = civicrm_api($this->_entity, 'Delete', $params);
|
||||
if ($result['is_error']) {
|
||||
echo "\nERROR line " . $this->row . ": " . $result['error_message'] . "\n";
|
||||
}
|
||||
else {
|
||||
echo "\nline " . $this->row . ": deleted\n";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
32
sites/all/modules/civicrm/bin/cli.php
Normal file
32
sites/all/modules/civicrm/bin/cli.php
Normal file
|
@ -0,0 +1,32 @@
|
|||
#!/usr/bin/env php
|
||||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright Tech To The People http:tttp.eu (c) 2008 |
|
||||
+--------------------------------------------------------------------+
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
|
||||
require_once 'cli.class.php';
|
||||
$cli = new civicrm_Cli();
|
||||
$cli->initialize() || die('Died during initialization');
|
||||
$cli->callApi() || die('Died during callApi');
|
54
sites/all/modules/civicrm/bin/cron.php
Normal file
54
sites/all/modules/civicrm/bin/cron.php
Normal file
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
|
||||
require_once '../civicrm.config.php';
|
||||
require_once 'CRM/Core/Config.php';
|
||||
require_once 'CRM/Utils/Request.php';
|
||||
$config = CRM_Core_Config::singleton();
|
||||
|
||||
CRM_Utils_System::authenticateScript(TRUE);
|
||||
|
||||
$job = CRM_Utils_Request::retrieve('job', 'String', CRM_Core_DAO::$_nullArray, FALSE, NULL, 'REQUEST');
|
||||
|
||||
require_once 'CRM/Core/JobManager.php';
|
||||
$facility = new CRM_Core_JobManager();
|
||||
|
||||
if ($job === NULL) {
|
||||
$facility->execute();
|
||||
}
|
||||
else {
|
||||
$ignored = array("name", "pass", "key", "job");
|
||||
$params = array();
|
||||
foreach ($_REQUEST as $name => $value) {
|
||||
if (!in_array($name, $ignored)) {
|
||||
$params[$name] = CRM_Utils_Request::retrieve($name, 'String', CRM_Core_DAO::$_nullArray, FALSE, NULL, 'REQUEST');
|
||||
}
|
||||
}
|
||||
$facility->setSingleRunParams('job', $job, $params, 'From cron.php');
|
||||
$facility->executeJobByAction('job', $job);
|
||||
}
|
40
sites/all/modules/civicrm/bin/csv/delete.php
Normal file
40
sites/all/modules/civicrm/bin/csv/delete.php
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright Tech To The People http:tttp.eu (c) 2011 |
|
||||
+--------------------------------------------------------------------+
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
* Delete records passed in via a csv file. You must have the record
|
||||
* id defined in the csv file.
|
||||
*
|
||||
* Usage:
|
||||
* php bin/csv/delete.php -e <entity> --file /path/to/csv/file [ -s site.org ]
|
||||
* e.g.: php bin/csv/delete.php -e Contact --file /tmp/delete.csv
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__DIR__) . '/cli.class.php';
|
||||
|
||||
$entityImporter = new civicrm_cli_csv_deleter();
|
||||
$entityImporter->run();
|
41
sites/all/modules/civicrm/bin/csv/export.php
Normal file
41
sites/all/modules/civicrm/bin/csv/export.php
Normal file
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright Tech To The People http:tttp.eu (c) 2011 |
|
||||
+--------------------------------------------------------------------+
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Export records in a csv format to standard out. Optionally
|
||||
* limit records by field/value pairs passed as arguments.
|
||||
*
|
||||
* Usage:
|
||||
* php bin/csv/export.php -e <entity> [ --field=value --field=value ] [ -s site.org ]
|
||||
* e.g.: php bin/csv/export.php -e Contact --email=jamie@progressivetech.org
|
||||
*
|
||||
*/
|
||||
require_once dirname(__DIR__) . '/cli.class.php';
|
||||
|
||||
$entityExporter = new civicrm_cli_csv_exporter();
|
||||
$entityExporter->run();
|
38
sites/all/modules/civicrm/bin/csv/import.php
Normal file
38
sites/all/modules/civicrm/bin/csv/import.php
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright Tech To The People http:tttp.eu (c) 2011 |
|
||||
+--------------------------------------------------------------------+
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
* Import records from a csv file passed as an argument.
|
||||
*
|
||||
* Usage:
|
||||
* php bin/csv/import.php -e <entity> --file /path/to/csv/file [ -s site.org ]
|
||||
* e.g.: php bin/csv/import.php -e Contact --file /tmp/import.csv
|
||||
*
|
||||
*/
|
||||
require_once dirname(__DIR__) . '/cli.class.php';
|
||||
|
||||
$entityImporter = new civicrm_cli_csv_importer();
|
||||
$entityImporter->run();
|
769
sites/all/modules/civicrm/bin/givi
Executable file
769
sites/all/modules/civicrm/bin/givi
Executable file
|
@ -0,0 +1,769 @@
|
|||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
// This is the minimalist denialist implementation that doesn't check it's
|
||||
// pre-conditions and will screw up if you don't know what you're doing.
|
||||
|
||||
/**
|
||||
* Manage the current working directory as a stack.
|
||||
*/
|
||||
class DirStack {
|
||||
protected $dirs;
|
||||
|
||||
/**
|
||||
* @param array $dirs
|
||||
*/
|
||||
public function __construct($dirs = array()) {
|
||||
$this->dirs = $dirs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $dir
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function push($dir) {
|
||||
$this->dirs[] = getcwd();
|
||||
if (!chdir($dir)) {
|
||||
throw new Exception("Failed to chdir($dir)");
|
||||
}
|
||||
}
|
||||
|
||||
public function pop() {
|
||||
$oldDir = array_pop($this->dirs);
|
||||
chdir($oldDir);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* FIXME: Why am I doing this? Can't we get a proper build-system for little
|
||||
* CLI tools -- and then use prepackaged libraries?
|
||||
*/
|
||||
class PullRequest {
|
||||
|
||||
/**
|
||||
* Given a link to a pull-request, determine which local repo
|
||||
* it applies to and fetch any metadata.
|
||||
*
|
||||
* @param string $url
|
||||
* @param array $repos list of locally known repos
|
||||
* @return PullRequest|NULL
|
||||
*/
|
||||
public static function get($url, $repos) {
|
||||
foreach ($repos as $repo => $relPath) {
|
||||
if (preg_match("/^https:\/\/github.com\/(.*)\/(civicrm-{$repo})\/pull\/([0-9]+)(|\/commits|\/files)$/", $url, $matches)) {
|
||||
list ($full, $githubUser, $githubRepo, $githubPr) = $matches;
|
||||
|
||||
$pr = new PullRequest();
|
||||
$pr->repo = $repo;
|
||||
$pr->data = HttpClient::getJson("https://api.github.com/repos/$githubUser/$githubRepo/pulls/$githubPr");
|
||||
if (empty($pr->data)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return $pr;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var string local repo name e.g. "core", "drupal"
|
||||
*/
|
||||
public $repo;
|
||||
|
||||
protected $data;
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getNumber() {
|
||||
return $this->data->number;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string name of the branch on the requestor's repo
|
||||
*/
|
||||
public function getRequestorBranch() {
|
||||
return $this->data->head->ref;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string URL of the requestor's repo
|
||||
*/
|
||||
public function getRequestorRepoUrl() {
|
||||
return $this->data->head->repo->git_url;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Givi
|
||||
*/
|
||||
class Givi {
|
||||
|
||||
/**
|
||||
* @var string 'checkout', 'begin', 'help', etc
|
||||
*/
|
||||
protected $action;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $baseBranch;
|
||||
|
||||
/**
|
||||
* @var array ($repoName => $gitRef)
|
||||
*/
|
||||
protected $branches;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $civiRoot = '.';
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $drupalVersion = 7;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $dryRun = FALSE;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $fetch = FALSE;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $force = FALSE;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $rebase = FALSE;
|
||||
|
||||
/**
|
||||
* @var string, the word 'all' or comma-delimited list of repo names
|
||||
*/
|
||||
protected $repoFilter = 'all';
|
||||
|
||||
/**
|
||||
* @var array ($repoName => $relPath)
|
||||
*/
|
||||
protected $repos;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $useGencode = FALSE;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $useSetup = FALSE;
|
||||
|
||||
/**
|
||||
* @var array, non-hyphenated arguments after the basedir
|
||||
*/
|
||||
protected $arguments;
|
||||
|
||||
/**
|
||||
* @var string, the name of this program
|
||||
*/
|
||||
protected $program;
|
||||
|
||||
/**
|
||||
* @var DirStack
|
||||
*/
|
||||
protected $dirStack;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->dirStack = new DirStack();
|
||||
$this->repos = array(
|
||||
'core' => '.',
|
||||
'backdrop' => 'backdrop',
|
||||
'drupal' => 'drupal',
|
||||
'joomla' => 'joomla',
|
||||
'packages' => 'packages',
|
||||
'wordpress' => 'WordPress',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $args
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function main($args) {
|
||||
if (!$this->parseOptions($args)) {
|
||||
printf("Error parsing arguments\n");
|
||||
$this->doHelp();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// All operations relative to civiRoot
|
||||
$this->dirStack->push($this->civiRoot);
|
||||
|
||||
// Filter branch list based on what repos actually exist
|
||||
foreach (array_keys($this->repos) as $repo) {
|
||||
if (!is_dir($this->repos[$repo])) {
|
||||
unset($this->repos[$repo]);
|
||||
}
|
||||
}
|
||||
if (!isset($this->repos['core']) || !isset($this->repos['packages'])) {
|
||||
return $this->returnError("Root appears to be invalid -- missing too many repos. Try --root=<dir>\n");
|
||||
}
|
||||
|
||||
$this->repos = $this->filterRepos($this->repoFilter, $this->repos);
|
||||
|
||||
// Run the action
|
||||
switch ($this->action) {
|
||||
case 'checkout':
|
||||
call_user_func_array(array($this, 'doCheckoutAll'), $this->arguments);
|
||||
break;
|
||||
|
||||
case 'fetch':
|
||||
call_user_func_array(array($this, 'doFetchAll'), $this->arguments);
|
||||
break;
|
||||
|
||||
case 'status':
|
||||
call_user_func_array(array($this, 'doStatusAll'), $this->arguments);
|
||||
break;
|
||||
|
||||
case 'begin':
|
||||
call_user_func_array(array($this, 'doBegin'), $this->arguments);
|
||||
break;
|
||||
|
||||
case 'resume':
|
||||
call_user_func_array(array($this, 'doResume'), $this->arguments);
|
||||
break;
|
||||
|
||||
case 'review':
|
||||
call_user_func_array(array($this, 'doReview'), $this->arguments);
|
||||
break;
|
||||
|
||||
//case 'merge-forward':
|
||||
// call_user_func_array(array($this, 'doMergeForward'), $this->arguments);
|
||||
// break;
|
||||
|
||||
case 'push':
|
||||
call_user_func_array(array($this, 'doPush'), $this->arguments);
|
||||
break;
|
||||
|
||||
case 'help':
|
||||
case '':
|
||||
$this->doHelp();
|
||||
break;
|
||||
|
||||
default:
|
||||
return $this->returnError("unrecognized action: {$this->action}\n");
|
||||
}
|
||||
|
||||
if ($this->useSetup) {
|
||||
$this->run('core', $this->civiRoot . '/bin', 'bash', 'setup.sh');
|
||||
}
|
||||
elseif ($this->useGencode) {
|
||||
$this->run('core', $this->civiRoot . '/xml', 'php', 'GenCode.php');
|
||||
}
|
||||
|
||||
$this->dirStack->pop();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $args
|
||||
* @return bool
|
||||
*/
|
||||
public function parseOptions($args) {
|
||||
$this->branches = array();
|
||||
$this->arguments = array();
|
||||
|
||||
foreach ($args as $arg) {
|
||||
if ($arg == '--fetch') {
|
||||
$this->fetch = TRUE;
|
||||
}
|
||||
elseif ($arg == '--rebase') {
|
||||
$this->rebase = TRUE;
|
||||
}
|
||||
elseif ($arg == '--dry-run' || $arg == '-n') {
|
||||
$this->dryRun = TRUE;
|
||||
}
|
||||
elseif ($arg == '--force' || $arg == '-f') {
|
||||
$this->force = TRUE;
|
||||
}
|
||||
elseif ($arg == '--gencode') {
|
||||
$this->useGencode = TRUE;
|
||||
}
|
||||
elseif ($arg == '--setup') {
|
||||
$this->useSetup = TRUE;
|
||||
}
|
||||
elseif (preg_match('/^--d([678])/', $arg, $matches)) {
|
||||
$this->drupalVersion = $matches[1];
|
||||
}
|
||||
elseif (preg_match('/^--root=(.*)/', $arg, $matches)) {
|
||||
$this->civiRoot = $matches[1];
|
||||
}
|
||||
elseif (preg_match('/^--repos=(.*)/', $arg, $matches)) {
|
||||
$this->repoFilter = $matches[1];
|
||||
}
|
||||
elseif (preg_match('/^--(core|packages|joomla|drupal|wordpress|backdrop)=(.*)/', $arg, $matches)) {
|
||||
$this->branches[$matches[1]] = $matches[2];
|
||||
}
|
||||
elseif (preg_match('/^-/', $arg)) {
|
||||
printf("unrecognized argument: %s\n", $arg);
|
||||
return FALSE;
|
||||
}
|
||||
else {
|
||||
$this->arguments[] = $arg;
|
||||
}
|
||||
}
|
||||
|
||||
$this->program = @array_shift($this->arguments);
|
||||
$this->action = @array_shift($this->arguments);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
public function doHelp() {
|
||||
$program = basename($this->program);
|
||||
echo "Givi - Coordinate git checkouts across CiviCRM repositories\n";
|
||||
echo "Scenario:\n";
|
||||
echo " You have cloned and forked the CiviCRM repos. Each of the repos has two\n";
|
||||
echo " remotes (origin + upstream). When working on a new PR, you generally want\n";
|
||||
echo " to checkout official code (eg upstream/master) in all repos, but 1-2 repos\n";
|
||||
echo " should use a custom branch (which tracks upstream/master).\n";
|
||||
echo "Usage:\n";
|
||||
echo " $program [options] checkout <branch>\n";
|
||||
echo " $program [options] fetch\n";
|
||||
echo " $program [options] status\n";
|
||||
echo " $program [options] begin <base-branch> [--core=<new-branch>|--drupal=<new-branch>|...] \n";
|
||||
echo " $program [options] resume [--rebase] <base-branch> [--core=<custom-branch>|--drupal=<custom-branch>|...] \n";
|
||||
echo " $program [options] review <base-branch> <pr-url-1> <pr-url-2>...\n";
|
||||
#echo " $program [options] merge-forward <maintenace-branch> <development-branch>\n";
|
||||
#echo " $program [options] push <remote> <branch>[:<branch>]\n";
|
||||
echo "Actions:\n";
|
||||
echo " checkout: Checkout same branch name on all repos\n";
|
||||
echo " fetch: Fetch remote changes on all repos\n";
|
||||
echo " status: Display status on all repos\n";
|
||||
echo " begin: Begin work on a new branch on some repo (and use base-branch for all others)\n";
|
||||
echo " resume: Resume work on an existing branch on some repo (and use base-branch for all others)\n";
|
||||
echo " review: Test work provided by someone else's pull-request. (If each repo has related PRs, then you can link to each of them.)\n";
|
||||
#echo " merge-forward: On each repo, merge changes from maintenance branch to development branch\n";
|
||||
#echo " push: On each repo, push a branch to a remote (Note: only intended for use with merge-forward)\n";
|
||||
echo "Common options:\n";
|
||||
echo " --dry-run: Don't do anything; only print commands that would be run\n";
|
||||
echo " --d6: Specify that Drupal branches should use 6.x-* prefixes\n";
|
||||
echo " --d7: Specify that Drupal branches should use 7.x-* prefixes (default)\n";
|
||||
echo " --d8: Specify that Drupal branches should use 8.x-* prefixes\n";
|
||||
echo " -f: When switching branches, proceed even if the index or the working tree differs from HEAD. This is used to throw away local changes.\n";
|
||||
echo " --fetch: Fetch the latest code before creating, updating, or checking-out anything\n";
|
||||
echo " --repos=X: Restrict operations to the listed repos (comma-delimited list) (default: all)";
|
||||
echo " --root=X: Specify CiviCRM root directory (default: .)\n";
|
||||
echo " --gencode: Run xml/GenCode after checking out code\n";
|
||||
echo " --setup: Run bin/setup.sh (incl xml/GenCode) after checking out code\n";
|
||||
echo "Special options:\n";
|
||||
echo " --core=X: Specify the branch to use on the core repository\n";
|
||||
echo " --packages=X: Specify the branch to use on the packages repository\n";
|
||||
echo " --backdrop=X: Specify the branch to use on the backdrop repository\n";
|
||||
echo " --drupal=X: Specify the branch to use on the drupal repository\n";
|
||||
echo " --joomla=X: Specify the branch to use on the joomla repository\n";
|
||||
echo " --wordpress=X: Specify the branch to use on the wordpress repository\n";
|
||||
echo " --rebase: Perform a rebase before starting work\n";
|
||||
echo "Known repositories:\n";
|
||||
foreach ($this->repos as $repo => $relPath) {
|
||||
printf(" %-12s: %s\n", $repo, realpath($this->civiRoot . DIRECTORY_SEPARATOR . $relPath));
|
||||
}
|
||||
echo "When using 'begin' or 'resume' with a remote base-branch, most repositories\n";
|
||||
echo "will have a detached HEAD. Only repos with an explicit branch will be real,\n";
|
||||
echo "local branches.\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $baseBranch
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function doCheckoutAll($baseBranch = NULL) {
|
||||
if (!$baseBranch) {
|
||||
return $this->returnError("Missing <branch>\n");
|
||||
}
|
||||
$branches = $this->resolveBranches($baseBranch, $this->branches);
|
||||
if ($this->fetch) {
|
||||
$this->doFetchAll();
|
||||
}
|
||||
|
||||
foreach ($this->repos as $repo => $relPath) {
|
||||
$filteredBranch = $this->filterBranchName($repo, $branches[$repo]);
|
||||
$this->run($repo, $relPath, 'git', 'checkout', $filteredBranch, $this->force ? '-f' : NULL);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function doStatusAll() {
|
||||
foreach ($this->repos as $repo => $relPath) {
|
||||
$this->run($repo, $relPath, 'git', 'status');
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $baseBranch
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function doBegin($baseBranch = NULL) {
|
||||
if (!$baseBranch) {
|
||||
return $this->returnError("Missing <base-branch>\n");
|
||||
}
|
||||
if (empty($this->branches)) {
|
||||
return $this->returnError("Must specify a custom branch for at least one repository.\n");
|
||||
}
|
||||
$branches = $this->resolveBranches($baseBranch, $this->branches);
|
||||
if ($this->fetch) {
|
||||
$this->doFetchAll();
|
||||
}
|
||||
|
||||
foreach ($this->repos as $repo => $relPath) {
|
||||
$filteredBranch = $this->filterBranchName($repo, $branches[$repo]);
|
||||
$filteredBaseBranch = $this->filterBranchName($repo, $baseBranch);
|
||||
|
||||
if ($filteredBranch == $filteredBaseBranch) {
|
||||
$this->run($repo, $relPath, 'git', 'checkout', $filteredBranch, $this->force ? '-f' : NULL);
|
||||
}
|
||||
else {
|
||||
$this->run($repo, $relPath, 'git', 'checkout', '-b', $filteredBranch, $filteredBaseBranch, $this->force ? '-f' : NULL);
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $baseBranch
|
||||
*
|
||||
* @return bool
|
||||
* @throws Exception
|
||||
*/
|
||||
public function doResume($baseBranch = NULL) {
|
||||
if (!$baseBranch) {
|
||||
return $this->returnError("Missing <base-branch>\n");
|
||||
}
|
||||
if (empty($this->branches)) {
|
||||
return $this->returnError("Must specify a custom branch for at least one repository.\n");
|
||||
}
|
||||
$branches = $this->resolveBranches($baseBranch, $this->branches);
|
||||
if ($this->fetch) {
|
||||
$this->doFetchAll();
|
||||
}
|
||||
|
||||
foreach ($this->repos as $repo => $relPath) {
|
||||
$filteredBranch = $this->filterBranchName($repo, $branches[$repo]);
|
||||
$filteredBaseBranch = $this->filterBranchName($repo, $baseBranch);
|
||||
|
||||
$this->run($repo, $relPath, 'git', 'checkout', $filteredBranch, $this->force ? '-f' : NULL);
|
||||
if ($filteredBranch != $filteredBaseBranch && $this->rebase) {
|
||||
list ($baseRemoteRepo, $baseRemoteBranch) = $this->parseBranchRepo($filteredBaseBranch);
|
||||
$this->run($repo, $relPath, 'git', 'pull', '--rebase', $baseRemoteRepo, $baseRemoteBranch);
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $baseBranch
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function doReview($baseBranch = NULL) {
|
||||
if (!$this->doCheckoutAll($baseBranch)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$args = func_get_args();
|
||||
array_shift($args); // $baseBranch
|
||||
|
||||
$pullRequests = array();
|
||||
foreach ($args as $prUrl) {
|
||||
$pullRequest = PullRequest::get($prUrl, $this->repos);
|
||||
if ($pullRequest) {
|
||||
$pullRequests[] = $pullRequest;
|
||||
}
|
||||
else {
|
||||
return $this->returnError("Invalid pull-request URL: $prUrl");
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($pullRequests as $pullRequest) {
|
||||
$repo = $pullRequest->repo;
|
||||
$branchName = 'pull-request-' . $pullRequest->getNumber();
|
||||
if ($this->hasLocalBranch($repo, $branchName)) {
|
||||
$this->run($repo, $this->repos[$repo], 'git', 'branch', '-D', $branchName);
|
||||
}
|
||||
$this->run($repo, $this->repos[$repo], 'git', 'checkout', '-b', $branchName); ## based on whatever was chosen by doCheckoutAll()
|
||||
$this->run($repo, $this->repos[$repo], 'git', 'pull', $pullRequest->getRequestorRepoUrl(), $pullRequest->getRequestorBranch());
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $newBranchRepo
|
||||
* @param $newBranchNames
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function doPush($newBranchRepo, $newBranchNames) {
|
||||
if (!$newBranchRepo) {
|
||||
return $this->returnError("Missing <remote>\n");
|
||||
}
|
||||
if (!$newBranchNames) {
|
||||
return $this->returnError("Missing <branch>[:<branch>]\n");
|
||||
}
|
||||
if (FALSE !== strpos($newBranchNames, ':')) {
|
||||
list ($newBranchFromName, $newBranchToName) = explode(':', $newBranchNames);
|
||||
foreach ($this->repos as $repo => $relPath) {
|
||||
$filteredFromName = $this->filterBranchName($repo, $newBranchFromName);
|
||||
$filteredToName = $this->filterBranchName($repo, $newBranchToName);
|
||||
|
||||
$this->run($repo, $relPath, 'git', 'push', $newBranchRepo, $filteredFromName . ':' . $filteredToName);
|
||||
}
|
||||
}
|
||||
else {
|
||||
foreach ($this->repos as $repo => $relPath) {
|
||||
$filteredName = $this->filterBranchName($repo, $newBranchNames);
|
||||
$this->run($repo, $relPath, 'git', 'push', $newBranchRepo, $filteredName);
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a branch exists locally
|
||||
*
|
||||
* @param string $repo
|
||||
* @param string $name branch name
|
||||
* @return bool
|
||||
*/
|
||||
public function hasLocalBranch($repo, $name) {
|
||||
$path = $this->repos[$repo] . '/.git/refs/heads/' . $name;
|
||||
return file_exists($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a ref name, determine the repo and branch
|
||||
*
|
||||
* FIXME: only supports $refs like "foo" (implicit origin) or "myremote/foo"
|
||||
*
|
||||
* @param $ref
|
||||
* @param string $defaultRemote
|
||||
*
|
||||
* @throws Exception
|
||||
* @return array
|
||||
*/
|
||||
public function parseBranchRepo($ref, $defaultRemote = 'origin') {
|
||||
$parts = explode('/', $ref);
|
||||
if (count($parts) == 1) {
|
||||
return array($defaultRemote, $parts[1]);
|
||||
}
|
||||
elseif (count($parts) == 2) {
|
||||
return $parts;
|
||||
}
|
||||
else {
|
||||
throw new Exception("Failed to parse branch name ($ref)");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run a command
|
||||
*
|
||||
* Any items after $command will be escaped and added to $command
|
||||
*
|
||||
* @param $repoName
|
||||
* @param string $runDir
|
||||
* @param string $command
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function run($repoName, $runDir, $command) {
|
||||
$this->dirStack->push($runDir);
|
||||
|
||||
$args = func_get_args();
|
||||
array_shift($args);
|
||||
array_shift($args);
|
||||
array_shift($args);
|
||||
foreach ($args as $arg) {
|
||||
if ($arg !== NULL) {
|
||||
$command .= ' ' . escapeshellarg($arg);
|
||||
}
|
||||
}
|
||||
printf("\n\n\nRUN [%s]: %s\n", $repoName, $command);
|
||||
if ($this->dryRun) {
|
||||
$r = NULL;
|
||||
}
|
||||
else {
|
||||
$r = system($command);
|
||||
}
|
||||
|
||||
$this->dirStack->pop();
|
||||
return $r;
|
||||
}
|
||||
|
||||
public function doFetchAll() {
|
||||
foreach ($this->repos as $repo => $relPath) {
|
||||
$this->run($repo, $relPath, 'git', 'fetch', '--all');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $default branch to use by default
|
||||
* @param $overrides
|
||||
*
|
||||
* @return array ($repoName => $gitRef)
|
||||
*/
|
||||
public function resolveBranches($default, $overrides) {
|
||||
$branches = $overrides;
|
||||
foreach ($this->repos as $repo => $relPath) {
|
||||
if (!isset($branches[$repo])) {
|
||||
$branches[$repo] = $default;
|
||||
}
|
||||
}
|
||||
return $branches;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $repoName
|
||||
* @param $branchName
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function filterBranchName($repoName, $branchName) {
|
||||
if ($branchName == '') {
|
||||
return '';
|
||||
}
|
||||
if ($repoName == 'drupal') {
|
||||
$parts = explode('/', $branchName);
|
||||
$last = $this->drupalVersion . '.x-' . array_pop($parts);
|
||||
array_push($parts, $last);
|
||||
return implode('/', $parts);
|
||||
}
|
||||
if ($repoName == 'backdrop') {
|
||||
$parts = explode('/', $branchName);
|
||||
$last = '1.x-' . array_pop($parts);
|
||||
array_push($parts, $last);
|
||||
return implode('/', $parts);
|
||||
}
|
||||
return $branchName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $filter e.g. "all" or "repo1,repo2"
|
||||
* @param array $repos ($repoName => $repoDir)
|
||||
*
|
||||
* @throws Exception
|
||||
* @return array ($repoName => $repoDir)
|
||||
*/
|
||||
public function filterRepos($filter, $repos) {
|
||||
if ($filter == 'all') {
|
||||
return $repos;
|
||||
}
|
||||
|
||||
$inclRepos = explode(',', $filter);
|
||||
$unknowns = array_diff($inclRepos, array_keys($repos));
|
||||
if (!empty($unknowns)) {
|
||||
throw new Exception("Unknown Repos: " . implode(',', $unknowns));
|
||||
}
|
||||
$unwanted = array_diff(array_keys($repos), $inclRepos);
|
||||
foreach ($unwanted as $repo) {
|
||||
unset($repos[$repo]);
|
||||
}
|
||||
return $repos;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $message
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function returnError($message) {
|
||||
echo "\nERROR: ", $message, "\n\n";
|
||||
$this->doHelp();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Class HttpClient
|
||||
*/
|
||||
class HttpClient {
|
||||
/**
|
||||
* @param $url
|
||||
* @param $file
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function download($url, $file) {
|
||||
// PHP native client is unreliable PITA for HTTPS
|
||||
if (exec("which wget")) {
|
||||
self::run('wget', '-q', '-O', $file, $url);
|
||||
}
|
||||
elseif (exec("which curl")) {
|
||||
self::run('curl', '-o', $file, $url);
|
||||
}
|
||||
|
||||
// FIXME: really detect errors
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $url
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getJson($url) {
|
||||
$file = tempnam(sys_get_temp_dir(), 'givi-json-');
|
||||
HttpClient::download($url, $file);
|
||||
$data = json_decode(file_get_contents($file));
|
||||
unlink($file);
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run a command
|
||||
*
|
||||
* Any items after $command will be escaped and added to $command
|
||||
*
|
||||
* @param string $command
|
||||
*
|
||||
* @internal param string $runDir
|
||||
* @return string
|
||||
*/
|
||||
public static function run($command) {
|
||||
$args = func_get_args();
|
||||
array_shift($args);
|
||||
foreach ($args as $arg) {
|
||||
$command .= ' ' . escapeshellarg($arg);
|
||||
}
|
||||
printf("\n\n\nRUN: %s\n", $command);
|
||||
$r = system($command);
|
||||
|
||||
return $r;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$givi = new Givi();
|
||||
$givi->main($argv);
|
52
sites/all/modules/civicrm/bin/migrate/export.php
Normal file
52
sites/all/modules/civicrm/bin/migrate/export.php
Normal file
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
function run() {
|
||||
session_start();
|
||||
|
||||
require_once '../../civicrm.config.php';
|
||||
require_once 'CRM/Core/Config.php';
|
||||
$config = CRM_Core_Config::singleton();
|
||||
|
||||
// this does not return on failure
|
||||
CRM_Utils_System::authenticateScript(TRUE);
|
||||
if (!CRM_Core_Permission::check('administer CiviCRM')) {
|
||||
CRM_Utils_System::authenticateAbort("User does not have required permission (administer CiviCRM).\n", TRUE);
|
||||
}
|
||||
|
||||
require_once 'CRM/Utils/Migrate/Export.php';
|
||||
$export = new CRM_Utils_Migrate_Export();
|
||||
$export->build();
|
||||
CRM_Utils_System::download('CustomGroupData.xml', 'text/plain', $export->toXML());
|
||||
}
|
||||
|
||||
run();
|
54
sites/all/modules/civicrm/bin/migrate/exportJSON.php
Normal file
54
sites/all/modules/civicrm/bin/migrate/exportJSON.php
Normal file
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
function run() {
|
||||
session_start();
|
||||
|
||||
require_once '../../civicrm.config.php';
|
||||
require_once 'CRM/Core/Config.php';
|
||||
$config = CRM_Core_Config::singleton();
|
||||
|
||||
// this does not return on failure
|
||||
CRM_Utils_System::authenticateScript(TRUE);
|
||||
if (!CRM_Core_Permission::check('administer CiviCRM')) {
|
||||
CRM_Utils_System::authenticateAbort("User does not have required permission (administer CiviCRM).\n", TRUE);
|
||||
}
|
||||
|
||||
$params = array();
|
||||
|
||||
require_once 'CRM/Utils/Migrate/ExportJSON.php';
|
||||
$export = new CRM_Utils_Migrate_ExportJSON($params);
|
||||
|
||||
$export->run('/tmp/export.json');
|
||||
}
|
||||
|
||||
run();
|
61
sites/all/modules/civicrm/bin/migrate/import.php
Normal file
61
sites/all/modules/civicrm/bin/migrate/import.php
Normal file
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
function run() {
|
||||
session_start();
|
||||
|
||||
if (!array_key_exists('file', $_GET) ||
|
||||
empty($_GET['file'])
|
||||
) {
|
||||
echo "Please send an input file to import<p>";
|
||||
exit();
|
||||
}
|
||||
|
||||
require_once '../../civicrm.config.php';
|
||||
require_once 'CRM/Core/Config.php';
|
||||
$config = CRM_Core_Config::singleton();
|
||||
|
||||
// this does not return on failure
|
||||
CRM_Utils_System::authenticateScript(TRUE);
|
||||
if (!CRM_Core_Permission::check('administer CiviCRM')) {
|
||||
CRM_Utils_System::authenticateAbort("User does not have required permission (administer CiviCRM).\n", TRUE);
|
||||
}
|
||||
|
||||
require_once 'CRM/Utils/Migrate/Import.php';
|
||||
$import = new CRM_Utils_Migrate_Import();
|
||||
|
||||
$import->run($_GET['file']);
|
||||
|
||||
echo "Import Done!";
|
||||
}
|
||||
|
||||
run();
|
52
sites/all/modules/civicrm/bin/migrate/importJSON.php
Normal file
52
sites/all/modules/civicrm/bin/migrate/importJSON.php
Normal file
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
function run() {
|
||||
session_start();
|
||||
|
||||
require_once '../../civicrm.config.php';
|
||||
require_once 'CRM/Core/Config.php';
|
||||
$config = CRM_Core_Config::singleton();
|
||||
|
||||
// this does not return on failure
|
||||
CRM_Utils_System::authenticateScript(TRUE);
|
||||
if (!CRM_Core_Permission::check('administer CiviCRM')) {
|
||||
CRM_Utils_System::authenticateAbort("User does not have required permission (administer CiviCRM).\n", TRUE);
|
||||
}
|
||||
|
||||
require_once 'CRM/Utils/Migrate/ImportJSON.php';
|
||||
$import = new CRM_Utils_Migrate_ImportJSON();
|
||||
|
||||
$import->run('/tmp/export.json');
|
||||
}
|
||||
|
||||
run();
|
54
sites/all/modules/civicrm/bin/migrate/move.php
Normal file
54
sites/all/modules/civicrm/bin/migrate/move.php
Normal file
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
function run() {
|
||||
session_start();
|
||||
|
||||
require_once '../../civicrm.config.php';
|
||||
require_once 'CRM/Core/Config.php';
|
||||
|
||||
$config = CRM_Core_Config::singleton();
|
||||
|
||||
// this does not return on failure
|
||||
CRM_Utils_System::authenticateScript(TRUE);
|
||||
if (!CRM_Core_Permission::check('administer CiviCRM')) {
|
||||
CRM_Utils_System::authenticateAbort("User does not have required permission (administer CiviCRM).\n", TRUE);
|
||||
}
|
||||
|
||||
require_once 'CRM/Core/BAO/ConfigSetting.php';
|
||||
$moveStatus = CRM_Core_BAO_ConfigSetting::doSiteMove();
|
||||
|
||||
echo $moveStatus . '<br />';
|
||||
echo ts("If no errors are displayed above, the site move steps have completed successfully. Please visit <a href=\"{$config->userFrameworkBaseURL}\">your moved site</a> and test the move.");
|
||||
}
|
||||
|
||||
run();
|
65
sites/all/modules/civicrm/bin/regen.sh
Executable file
65
sites/all/modules/civicrm/bin/regen.sh
Executable file
|
@ -0,0 +1,65 @@
|
|||
#!/usr/bin/env /bin/bash
|
||||
set -e
|
||||
set -x
|
||||
|
||||
source `dirname $0`/setup.conf
|
||||
source `dirname $0`/setup.lib.sh
|
||||
|
||||
# someone might want to use empty password for development,
|
||||
# let's make it possible - we asked before.
|
||||
if [ -z $DBPASS ]; then # password still empty
|
||||
PASSWDSECTION=""
|
||||
else
|
||||
PASSWDSECTION="-p$DBPASS"
|
||||
fi
|
||||
|
||||
pushd .
|
||||
cd $CIVISOURCEDIR
|
||||
# svn up .
|
||||
cd $CIVISOURCEDIR/bin
|
||||
./setup.sh
|
||||
cd $CIVISOURCEDIR/sql
|
||||
|
||||
echo; echo "Dropping civicrm_* tables from database $DBNAME"
|
||||
# mysqladmin -f -u $DBUSER $PASSWDSECTION $DBARGS drop $DBNAME
|
||||
MYSQLCMD=$(mysql_cmd)
|
||||
MYSQLADMCMD=$(mysqladmin_cmd)
|
||||
MYSQLDUMP=$(mysqldump_cmd)
|
||||
echo "SELECT table_name FROM information_schema.TABLES WHERE TABLE_SCHEMA='${DBNAME}' AND TABLE_TYPE = 'VIEW'" \
|
||||
| $MYSQLCMD \
|
||||
| grep '^\(civicrm_\|log_civicrm_\)' \
|
||||
| awk -v NOFOREIGNCHECK='SET FOREIGN_KEY_CHECKS=0;' 'BEGIN {print NOFOREIGNCHECK}{print "drop view " $1 ";"}' \
|
||||
| $MYSQLCMD
|
||||
echo "SELECT table_name FROM information_schema.TABLES WHERE TABLE_SCHEMA='${DBNAME}' AND TABLE_TYPE = 'BASE TABLE'" \
|
||||
| $MYSQLCMD \
|
||||
| grep '^\(civicrm_\|log_civicrm_\)' \
|
||||
| awk -v NOFOREIGNCHECK='SET FOREIGN_KEY_CHECKS=0;' 'BEGIN {print NOFOREIGNCHECK}{print "drop table " $1 ";"}' \
|
||||
| $MYSQLCMD
|
||||
|
||||
$MYSQLCMD < civicrm.mysql
|
||||
$MYSQLCMD < civicrm_data.mysql
|
||||
$MYSQLCMD < civicrm_sample.mysql
|
||||
echo "DROP TABLE IF EXISTS zipcodes" | $MYSQLCMD
|
||||
$MYSQLCMD < zipcodes.mysql
|
||||
|
||||
## For first boot on fresh DB, boot CMS before CRM.
|
||||
cms_eval 'civicrm_initialize();'
|
||||
|
||||
php GenerateData.php
|
||||
|
||||
## Prune local data
|
||||
$MYSQLCMD -e "DROP TABLE zipcodes; DROP TABLE IF EXISTS civicrm_install_canary; UPDATE civicrm_domain SET config_backend = NULL; DELETE FROM civicrm_extension; DELETE FROM civicrm_cache; DELETE FROM civicrm_setting;"
|
||||
TABLENAMES=$( echo "show tables like 'civicrm_%'" | $MYSQLCMD | grep ^civicrm_ | xargs )
|
||||
|
||||
cd $CIVISOURCEDIR/sql
|
||||
|
||||
$MYSQLDUMP -cent --skip-triggers $DBNAME $TABLENAMES > civicrm_generated.mysql
|
||||
#cat civicrm_sample_report.mysql >> civicrm_generated.mysql
|
||||
cat civicrm_sample_custom_data.mysql >> civicrm_generated.mysql
|
||||
#cat civicrm_devel_config.mysql >> civicrm_generated.mysql
|
||||
cat civicrm_dummy_processor.mysql >> civicrm_generated.mysql
|
||||
$MYSQLADMCMD -f drop $DBNAME
|
||||
$MYSQLADMCMD create $DBNAME
|
||||
$MYSQLCMD < civicrm.mysql
|
||||
$MYSQLCMD < civicrm_generated.mysql
|
||||
popd
|
59
sites/all/modules/civicrm/bin/setup.conf.txt
Normal file
59
sites/all/modules/civicrm/bin/setup.conf.txt
Normal file
|
@ -0,0 +1,59 @@
|
|||
# Define the path for civicrm source directory here
|
||||
CIVISOURCEDIR=
|
||||
|
||||
# define your schema file name here, will be overriden by
|
||||
# FIRST command line argument if given
|
||||
SCHEMA=schema/Schema.xml
|
||||
|
||||
## define your database host and port here
|
||||
DBHOST=
|
||||
DBPORT=
|
||||
|
||||
# define your database name here, will be overriden by
|
||||
# SECOND command line argument if given
|
||||
DBNAME=
|
||||
|
||||
# define your database usernamename here, will be overriden by
|
||||
# THIRD command line argument if given
|
||||
DBUSER=
|
||||
|
||||
# define your database password here, will be overriden by
|
||||
# FOURTH command line argument if given
|
||||
DBPASS=
|
||||
|
||||
# any extra args you need in your mysql connect string
|
||||
# number of arguments should be specified within ""
|
||||
# FIFTH command line argument if given
|
||||
DBARGS=""
|
||||
|
||||
# set your PHP5 bin dir path here, if it's not in PATH
|
||||
# The path should be terminated with dir separator!
|
||||
PHP5PATH=
|
||||
|
||||
# Set a special DB load filename here for custom installs
|
||||
# If a filename is passed, civicrm_data.mysql AND the
|
||||
# passed file will be loaded instead of civicrm_generated.mysql.
|
||||
# The DBLOAD file must be in the sql directory.
|
||||
DBLOAD=
|
||||
|
||||
# Set a special SQL filename here which you want to load
|
||||
# IN ADDITION TO either civicrm_generated or civicrm_data.
|
||||
# The DBADD file must be in the sql directory.
|
||||
# DBADD=
|
||||
|
||||
# GenCode produces localized data files for all known
|
||||
# locales. This is good for stable-releases but
|
||||
# cumbersome during development. To speed it up,
|
||||
# list the desired locales.
|
||||
# export CIVICRM_LOCALES=en_US,fr_FR
|
||||
|
||||
# GenCode produces some CMS-specific config files
|
||||
# If omitted, defaults to drupal.
|
||||
GENCODE_CMS=""
|
||||
# GENCODE_CMS=drupal
|
||||
# GENCODE_CMS=wordpress
|
||||
|
||||
# GenCode is relatively slow; and, usually, it only needs
|
||||
# to run if the gencode files have changed. Set
|
||||
# this option to enable caching (and speed up setup.sh)
|
||||
# export CIVICRM_GENCODE_DIGEST=/tmp/gencode.md5
|
74
sites/all/modules/civicrm/bin/setup.lib.sh
Normal file
74
sites/all/modules/civicrm/bin/setup.lib.sh
Normal file
|
@ -0,0 +1,74 @@
|
|||
function _mysql_vars() {
|
||||
# someone might want to use empty password for development,
|
||||
# let's make it possible - we asked before.
|
||||
if [ -z $DBPASS ]; then # password still empty
|
||||
PASSWDSECTION=""
|
||||
else
|
||||
PASSWDSECTION="-p$DBPASS"
|
||||
fi
|
||||
|
||||
HOSTSECTTION=""
|
||||
if [ ! -z "$DBHOST" ]; then
|
||||
HOSTSECTION="-h $DBHOST"
|
||||
fi
|
||||
|
||||
PORTSECTION=""
|
||||
if [ ! -z "$DBPORT" ]; then
|
||||
PORTSECTION="-P $DBPORT"
|
||||
fi
|
||||
}
|
||||
|
||||
function mysql_cmd() {
|
||||
_mysql_vars
|
||||
echo "mysql -u$DBUSER $PASSWDSECTION $HOSTSECTION $PORTSECTION $DBARGS $DBNAME"
|
||||
}
|
||||
|
||||
function mysqladmin_cmd() {
|
||||
_mysql_vars
|
||||
echo "mysqladmin -u$DBUSER $PASSWDSECTION $HOSTSECTION $PORTSECTION $DBARGS"
|
||||
}
|
||||
|
||||
function mysqldump_cmd() {
|
||||
_mysql_vars
|
||||
echo "mysqldump -u$DBUSER $PASSWDSECTION $HOSTSECTION $PORTSECTION $DBARGS"
|
||||
}
|
||||
|
||||
## Pick the first available command. If none, then abort.
|
||||
## example: COMPOSER=$(pickcmd composer composer.phar)
|
||||
function pickcmd() {
|
||||
for name in "$@" ; do
|
||||
if which $name >> /dev/null ; then
|
||||
echo $name
|
||||
return
|
||||
fi
|
||||
done
|
||||
echo "ERROR: Failed to find any of these commands: $@"
|
||||
exit 1
|
||||
}
|
||||
|
||||
## usage: has_commands <cmd1> <cmd2> ...
|
||||
function has_commands() {
|
||||
for cmd in "$@" ; do
|
||||
if ! which $cmd >> /dev/null ; then
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
return 0
|
||||
}
|
||||
|
||||
## Execute some PHP within CMS context
|
||||
## usage: cms_eval '<php-code>'
|
||||
function cms_eval() {
|
||||
case "$GENCODE_CMS" in
|
||||
Drupal*)
|
||||
drush ev "$1"
|
||||
;;
|
||||
WordPress*)
|
||||
wp eval "$1"
|
||||
;;
|
||||
*)
|
||||
echo "Cannot boot (GENCODE_CMS=$GENCODE_CMS)" > /dev/stderr
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue