/**
  * Class constructor
  *
  * @access private
  */
 function __construct()
 {
     global $civicrm_root;
     $config = CRM_Core_Config::singleton();
     $localfile = $civicrm_root . DIRECTORY_SEPARATOR . self::LOCALFILE_NAME;
     $cachefile = $config->uploadDir . self::CACHEFILE_NAME;
     if ($config->versionCheck && file_exists($localfile)) {
         require_once $localfile;
         if (function_exists('civicrmVersion')) {
             $info = civicrmVersion();
             $this->localVersion = $info['version'];
         }
         $expiryTime = time() - self::CACHEFILE_EXPIRE;
         // if there's a cachefile and it's not stale use it to
         // read the latestVersion, else read it from the Internet
         if (file_exists($cachefile) and filemtime($cachefile) > $expiryTime) {
             $this->latestVersion = file_get_contents($cachefile);
         } else {
             // we have to set the error handling to a dummy function, otherwise
             // if the URL is not working (e.g., due to our server being down)
             // the users would be presented with an unsuppressable warning
             ini_set('default_socket_timeout', self::CHECK_TIMEOUT);
             set_error_handler(array('CRM_Utils_VersionCheck', 'downloadError'));
             $hash = md5($config->userFrameworkBaseURL);
             $url = self::LATEST_VERSION_AT . "?version={$this->localVersion}&uf={$config->userFramework}&hash={$hash}&lang={$config->lcMessages}&ufv={$config->userFrameworkVersion}";
             // add PHP and MySQL versions
             $dao = new CRM_Core_DAO();
             $dao->query('SELECT VERSION() AS version');
             $dao->fetch();
             $url .= '&MySQL=' . $dao->version . '&PHP=' . phpversion();
             $tables = array('CRM_Activity_DAO_Activity' => 'is_test = 0', 'CRM_Case_DAO_Case' => NULL, 'CRM_Contact_DAO_Contact' => NULL, 'CRM_Contact_DAO_Relationship' => NULL, 'CRM_Contribute_DAO_Contribution' => 'is_test = 0', 'CRM_Contribute_DAO_ContributionPage' => 'is_active = 1', 'CRM_Contribute_DAO_ContributionProduct' => NULL, 'CRM_Contribute_DAO_Widget' => 'is_active = 1', 'CRM_Core_DAO_Discount' => NULL, 'CRM_Price_DAO_SetEntity' => NULL, 'CRM_Core_DAO_UFGroup' => 'is_active = 1', 'CRM_Event_DAO_Event' => 'is_active = 1', 'CRM_Event_DAO_Participant' => 'is_test = 0', 'CRM_Friend_DAO_Friend' => 'is_active = 1', 'CRM_Grant_DAO_Grant' => NULL, 'CRM_Mailing_DAO_Mailing' => 'is_completed = 1', 'CRM_Member_DAO_Membership' => 'is_test = 0', 'CRM_Member_DAO_MembershipBlock' => 'is_active = 1', 'CRM_Pledge_DAO_Pledge' => 'is_test = 0', 'CRM_Pledge_DAO_PledgeBlock' => NULL);
             // add &key=count pairs to $url, where key is the last part of the DAO
             foreach ($tables as $daoName => $where) {
                 require_once str_replace('_', '/', $daoName) . '.php';
                 eval("\$dao = new {$daoName};");
                 if ($where) {
                     $dao->whereAdd($where);
                 }
                 $url .= '&' . array_pop(explode('_', $daoName)) . "={$dao->count()}";
             }
             // get active payment processor types
             $dao = new CRM_Core_DAO_PaymentProcessor();
             $dao->is_active = 1;
             $dao->find();
             $ppTypes = array();
             while ($dao->fetch()) {
                 $ppTypes[] = $dao->payment_processor_type;
             }
             // add the .-separated list of the processor types (urlencoded just in case)
             $url .= '&PPTypes=' . urlencode(implode('.', array_unique($ppTypes)));
             // get the latest version using the stats-carrying $url
             $this->latestVersion = file_get_contents($url);
             ini_restore('default_socket_timeout');
             restore_error_handler();
             if (!preg_match('/^\\d+\\.\\d+\\.\\d+$/', $this->latestVersion)) {
                 $this->latestVersion = NULL;
             }
             if (!$this->latestVersion) {
                 return;
             }
             $fp = @fopen($cachefile, 'w');
             if (!$fp) {
                 $message = ts('Do not have permission to write to file: %1', array(1 => $cachefile));
                 CRM_Core_Session::setStatus($message);
                 return;
             }
             fwrite($fp, $this->latestVersion);
             fclose($fp);
         }
     }
 }
Example #2
0
 /**
  * undocumented function
  *
  * @return void
  **/
 public function uninstall()
 {
     if (!array_key_exists($this->ext->key, $this->paymentProcessorTypes)) {
         CRM_Core_Error::fatal('This payment processor type is not registered.');
     }
     require_once 'CRM/Core/PseudoConstant.php';
     $paymentProcessors = CRM_Core_PseudoConstant::paymentProcessor(TRUE);
     require_once "CRM/Core/DAO/PaymentProcessor.php";
     foreach ($paymentProcessors as $id => $name) {
         $dao = new CRM_Core_DAO_PaymentProcessor();
         $dao->id = $id;
         $dao->find();
         while ($dao->fetch()) {
             if ($dao->payment_processor_type == $this->ext->name) {
                 CRM_Core_Error::fatal('Cannot uninstall this extension - there is at least one payment processor using payment processor type provided by it.');
             }
         }
     }
     require_once "CRM/Core/BAO/PaymentProcessorType.php";
     CRM_Core_BAO_PaymentProcessorType::del($this->paymentProcessorTypes[$this->ext->key]);
 }
 /**
  * Function to get the payment processor details
  * 
  * @param  int    $paymentProcessorID payment processor id
  * @param  string $mode               payment mode ie test or live  
  * 
  * @return array  associated array with payment processor related fields
  * @static
  * @access public 
  */
 static function getPayment($paymentProcessorID, $mode)
 {
     if (!$paymentProcessorID) {
         CRM_Core_Error::fatal(ts('Invalid value passed to getPayment function'));
     }
     $dao = new CRM_Core_DAO_PaymentProcessor();
     $dao->id = $paymentProcessorID;
     $dao->is_active = 1;
     if (!$dao->find(true)) {
         return null;
     }
     if ($mode == 'test') {
         $testDAO = new CRM_Core_DAO_PaymentProcessor();
         $testDAO->name = $dao->name;
         $testDAO->is_active = 1;
         $testDAO->is_test = 1;
         if (!$testDAO->find(true)) {
             CRM_Core_Error::fatal(ts('Could not retrieve payment processor details'));
         }
         return self::buildPayment($testDAO);
     } else {
         return self::buildPayment($dao);
     }
 }
Example #4
0
 /**
  * class constructor
  */
 function __construct()
 {
     parent::__construct();
 }
 /**
  * returns the list of fields that can be exported
  *
  * @access public
  * return array
  * @static
  */
 static function &export($prefix = false)
 {
     if (!self::$_export) {
         self::$_export = array();
         $fields = self::fields();
         foreach ($fields as $name => $field) {
             if (CRM_Utils_Array::value('export', $field)) {
                 if ($prefix) {
                     self::$_export['payment_processor'] =& $fields[$name];
                 } else {
                     self::$_export[$name] =& $fields[$name];
                 }
             }
         }
     }
     return self::$_export;
 }
 /**
  * Browse all payment processors.
  *
  * @return void
  * @access public
  * @static
  */
 function browse($action = NULL)
 {
     // get all custom groups sorted by weight
     $paymentProcessor = array();
     $dao = new CRM_Core_DAO_PaymentProcessor();
     $dao->is_test = 0;
     $dao->domain_id = CRM_Core_Config::domainID();
     $dao->orderBy('name');
     $dao->find();
     while ($dao->fetch()) {
         $paymentProcessor[$dao->id] = array();
         CRM_Core_DAO::storeValues($dao, $paymentProcessor[$dao->id]);
         // form all action links
         $action = array_sum(array_keys($this->links()));
         // update enable/disable links.
         if ($dao->is_active) {
             $action -= CRM_Core_Action::ENABLE;
         } else {
             $action -= CRM_Core_Action::DISABLE;
         }
         $paymentProcessor[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), $action, array('id' => $dao->id));
     }
     $this->assign('rows', $paymentProcessor);
 }
 function updatePaymentProcessor(&$values, $domainID, $test)
 {
     $dao = new CRM_Core_DAO_PaymentProcessor();
     $dao->id = $test ? $this->_testID : $this->_id;
     $dao->domain_id = $domainID;
     $dao->is_test = $test;
     $dao->is_default = CRM_Utils_Array::value('is_default', $values, 0);
     $dao->is_active = CRM_Utils_Array::value('is_active', $values, 0);
     $dao->name = $values['name'];
     $dao->description = $values['description'];
     $dao->payment_processor_type = $values['payment_processor_type'];
     foreach ($this->_fields as $field) {
         $fieldName = $test ? "test_{$field['name']}" : $field['name'];
         $dao->{$field['name']} = trim(CRM_Utils_Array::value($fieldName, $values));
         if (empty($dao->{$field['name']})) {
             $dao->{$field['name']} = 'null';
         }
     }
     // also copy meta fields from the info DAO
     $dao->is_recur = $this->_ppDAO->is_recur;
     $dao->billing_mode = $this->_ppDAO->billing_mode;
     $dao->class_name = $this->_ppDAO->class_name;
     $dao->payment_type = $this->_ppDAO->payment_type;
     $dao->save();
 }
 static function getPayments($paymentProcessorIDs, $mode)
 {
     if (!$paymentProcessorIDs) {
         CRM_Core_Error::fatal(ts('Invalid value passed to getPayment function'));
     }
     foreach ($paymentProcessorIDs as $paymentProcessorID) {
         $dao = new CRM_Core_DAO_PaymentProcessor();
         $dao->id = $paymentProcessorID;
         $dao->is_active = 1;
         if (!$dao->find(TRUE)) {
             return NULL;
         }
         if ($mode == 'test') {
             $testDAO = new CRM_Core_DAO_PaymentProcessor();
             $testDAO->name = $dao->name;
             $testDAO->is_active = 1;
             $testDAO->is_test = 1;
             if (!$testDAO->find(TRUE)) {
                 CRM_Core_Error::fatal(ts('Could not retrieve payment processor details'));
             }
             $paymentDAO[$testDAO->id] = self::buildPayment($testDAO);
         } else {
             $paymentDAO[$dao->id] = self::buildPayment($dao);
         }
     }
     asort($paymentDAO);
     return $paymentDAO;
 }