Example #1
0
 /**
  * Ensure that modified_date hasn't changed in the underlying DB
  *
  * @param array $fields  the input form values
  * @param array $files   the uploaded files if any
  * @param array $options additional user data
  *
  * @return true if no errors, else array of errors
  * @access public
  * @static
  */
 static function formRule($fields, $files, $contactID = NULL)
 {
     $errors = array();
     $timestamps = CRM_Contact_BAO_Contact::getTimestamps($contactID);
     if ($fields['modified_date'] != $timestamps['modified_date']) {
         // Inline buttons generated via JS
         $open = sprintf("<span id='update_modified_date' data:latest_modified_date='%s'>", $timestamps['modified_date']);
         $close = "</span>";
         $errors['modified_date'] = $open . ts('This record was modified by another user!') . $close;
     }
     return empty($errors) ? TRUE : $errors;
 }
Example #2
0
 /**
  * Helper for testing timestamp manipulation.
  *
  * Create a contact and perform a series of steps with it; after each
  * step, ensure that the contact's modified_date has increased.
  *
  * @param array $callbacks
  *   ($name => $callable).
  */
 public function _testTimestamps($callbacks)
 {
     CRM_Core_DAO::triggerRebuild();
     $contactId = $this->individualCreate();
     $origTimestamps = CRM_Contact_BAO_Contact::getTimestamps($contactId);
     $this->assertRegexp('/^\\d\\d\\d\\d-\\d\\d-\\d\\d /', $origTimestamps['created_date']);
     $this->assertRegexp('/^\\d\\d\\d\\d-\\d\\d-\\d\\d /', $origTimestamps['modified_date']);
     $this->assertTrue($origTimestamps['created_date'] <= $origTimestamps['modified_date']);
     $prevTimestamps = $origTimestamps;
     foreach ($callbacks as $callbackName => $callback) {
         sleep(1);
         // advance clock by 1 second to ensure timestamps change
         $callback($contactId);
         $newTimestamps = CRM_Contact_BAO_Contact::getTimestamps($contactId);
         $this->assertRegexp('/^\\d\\d\\d\\d-\\d\\d-\\d\\d /', $newTimestamps['created_date'], "Malformed created_date (after {$callbackName})");
         $this->assertRegexp('/^\\d\\d\\d\\d-\\d\\d-\\d\\d /', $newTimestamps['modified_date'], "Malformed modified_date (after {$callbackName})");
         $this->assertEquals($origTimestamps['created_date'], $newTimestamps['created_date'], "Changed created_date (after {$callbackName})");
         $this->assertTrue($prevTimestamps['modified_date'] < $newTimestamps['modified_date'], "Misordered modified_date (after {$callbackName})");
         $prevTimestamps = $newTimestamps;
     }
     $this->contactDelete($contactId);
 }
Example #3
0
 /**
  * Return any post-save data.
  *
  * @param int $contactID
  *
  * @return array
  *   extra options to return in JSON
  */
 public static function getResponse($contactID)
 {
     $timestamps = CRM_Contact_BAO_Contact::getTimestamps($contactID);
     return array('oplock_ts' => $timestamps['modified_date']);
 }