Merge branch 'develop' of github.com:cerebrate-project/cerebrate into develop
commit
0ba6310434
|
@ -199,22 +199,22 @@ class FastUserEnrolmentCommand extends Command
|
||||||
$this->loadModel('Organisations');
|
$this->loadModel('Organisations');
|
||||||
$updatedData = [];
|
$updatedData = [];
|
||||||
foreach ($data as $entry) {
|
foreach ($data as $entry) {
|
||||||
$new = [
|
$individual = $this->getIndividualByEmail($entry[$this->individual_email_column]);
|
||||||
'individual_id' => $this->getIndividualByEmail($entry[$this->individual_email_column]),
|
$organisation = $this->getOrganisationsByName($entry[$this->organisation_name_column]);
|
||||||
'organisation_id' => $this->getOrganisationsByName($entry[$this->organisation_name_column]),
|
if (empty($organisation)) {
|
||||||
'type' => $this->alignment_type,
|
|
||||||
'individual_email' => $entry[$this->individual_email_column],
|
|
||||||
];
|
|
||||||
if (empty($new['organisation_id'])) {
|
|
||||||
$this->io->error("Error while parsing source data. Could not find organisation with name: " . $entry[$this->organisation_name_column]);
|
$this->io->error("Error while parsing source data. Could not find organisation with name: " . $entry[$this->organisation_name_column]);
|
||||||
die(1);
|
die(1);
|
||||||
}
|
}
|
||||||
if (empty($new['individual_id'])) {
|
if (empty($individual)) {
|
||||||
$this->io->error("Error while parsing source data. Could not find individuals with email: " . $entry[$this->individual_email_column]);
|
$this->io->error("Error while parsing source data. Could not find individuals with email: " . $entry[$this->individual_email_column]);
|
||||||
die(1);
|
die(1);
|
||||||
}
|
}
|
||||||
$new['individual_id'] = $new['individual_id']['id'];
|
$new = [
|
||||||
$new['organisation_id'] = $new['organisation_id']['id'];
|
'individual_id' => $individual->id,
|
||||||
|
'organisation_id' => $organisation->id,
|
||||||
|
'type' => $this->alignment_type,
|
||||||
|
'individual_email' => $entry[$this->individual_email_column],
|
||||||
|
];
|
||||||
$updatedData[] = $new;
|
$updatedData[] = $new;
|
||||||
}
|
}
|
||||||
return $updatedData;
|
return $updatedData;
|
||||||
|
@ -224,14 +224,14 @@ class FastUserEnrolmentCommand extends Command
|
||||||
{
|
{
|
||||||
return $this->Individuals->find()->where([
|
return $this->Individuals->find()->where([
|
||||||
'email' => $email,
|
'email' => $email,
|
||||||
])->first()->toArray();
|
])->first();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getOrganisationsByName($name)
|
private function getOrganisationsByName($name)
|
||||||
{
|
{
|
||||||
return $this->Organisations->find()->where([
|
return $this->Organisations->find()->where([
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
])->first()->toArray();
|
])->first();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getDataFromFile($path)
|
private function getDataFromFile($path)
|
||||||
|
|
|
@ -73,7 +73,11 @@ class CRUDComponent extends Component
|
||||||
$query->select($options['fields']);
|
$query->select($options['fields']);
|
||||||
}
|
}
|
||||||
if (!empty($options['order'])) {
|
if (!empty($options['order'])) {
|
||||||
$query->order($options['order']);
|
$orderFields = array_keys($options['order']);
|
||||||
|
if ($this->_validOrderFields($orderFields)) {
|
||||||
|
$query->order($options['order']);
|
||||||
|
$this->Controller->paginate['order'] = $options['order'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ($this->Controller->ParamHandler->isRest()) {
|
if ($this->Controller->ParamHandler->isRest()) {
|
||||||
if ($this->metaFieldsSupported()) {
|
if ($this->metaFieldsSupported()) {
|
||||||
|
@ -1581,4 +1585,34 @@ class CRUDComponent extends Component
|
||||||
}
|
}
|
||||||
return $typeMap;
|
return $typeMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function _validOrderFields($fields): bool
|
||||||
|
{
|
||||||
|
if (!is_array($fields)) {
|
||||||
|
$fields = [$fields];
|
||||||
|
}
|
||||||
|
foreach ($fields as $field) {
|
||||||
|
$exploded = explode('.', $field);
|
||||||
|
if (count($exploded) > 1) {
|
||||||
|
$model = $exploded[0];
|
||||||
|
$subField = $exploded[1];
|
||||||
|
if ($model == $this->Table->getAlias()) {
|
||||||
|
if (empty($this->Table->getSchema()->typeMap()[$subField])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$association = $this->Table->associations()->get($model);
|
||||||
|
$associatedTable = $association->getTarget();
|
||||||
|
if (empty($associatedTable->getSchema()->typeMap()[$subField])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (empty($this->Table->getSchema()->typeMap()[$field])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue