Skip to content
Snippets Groups Projects

upgrade of civix to 23.02.01

Merged VangelisP requested to merge 1.x-1.1.0 into 1.x
Files
12
+ 94
0
<?php
use CRM_Benchmarktools_BAO_Benchmarktools as B;
class CRM_Benchmarktools_BAO_API4benchmarks {
public static function runTest($count = 1, $action = 'apiv4_contact_create') {
if ($action == 'apiv4_contact_create') {
$results = self::createAPIv4Contacts($count);
return $results;
}
elseif ($action == 'apiv4_contact_delete') {
$results = self::deleteAPIv4Contacts($count);
return $results;
}
}
/**
* createAPIv4Contacts
*
* @param mixed $count
* @return void
*/
public static function createAPIv4Contacts($count) {
// Count the statistics
$starttime = microtime(TRUE);
// Get the loop for the count
$intCount = 0;
while ($intCount < $count) {
// Get some random names
$data = B::getRandomNames(1);
$names = reset($data);
$names['external_identifier'] = 'RND-' . rand(1111111111,9999999999);
// Create the contact(s)
$results = \Civi\Api4\Contact::create(FALSE)
->addValue('first_name', $names['first_name'])
->addValue('last_name', $names['last_name'])
->addValue('external_identifier', $names['external_identifier'])
->addValue('contact_type', 'Individual')
->execute();
$intCount++;
}
$stepTime = microtime(TRUE);
$execTime = number_format((float) ($stepTime - $starttime), 3);
$results = [
'process_time' => $execTime,
'type' => 'apiv4_contact_create',
'count' => $count,
];
return $results;
}
/**
* deleteAPIv4Contacts
*
* @param mixed $count
* @return void
*/
public static function deleteAPIv4Contacts($count) {
$actualCount = 0;
// First get a list of contacts, up to the limit of the $count
$contacts = \Civi\Api4\Contact::get(FALSE)
->addSelect('id')
->addWhere('external_identifier', 'LIKE', 'RND-%')
->setLimit($count)
->execute();
// Start the counter
// Count the statistics
$starttime = microtime(TRUE);
foreach ($contacts as $contact) {
$results = \Civi\Api4\Contact::delete(FALSE)
->addWhere('id', '=', $contact['id'])
->execute();
$actualCount++;
}
$stepTime = microtime(TRUE);
$execTime = number_format((float) ($stepTime - $starttime), 3);
$results = [
'process_time' => $execTime,
'type' => 'apiv4_contact_delete',
'count' => $actualCount,
];
return $results;
}
}
Loading