Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

33244 hot fix enterprise deactivated fields will lead to critical error #497

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions plugin/EstateList.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,33 @@ private function filterActiveInputFields($inputs): DataView
$inputs->setFields($activeInputs);
return $inputs;
}

/**
* @param $inputs
* @return DataView
*
*/

private function filterActiveInputFilterableFields($inputs): DataView
{
$activeInputs = [];
$recordType = onOfficeSDK::MODULE_ESTATE;
$pFieldsCollection = new FieldsCollection();
$pFieldBuilderShort = $this->_pEnvironment->getContainer()->get(FieldsCollectionBuilderShort::class);
$pFieldBuilderShort
->addFieldsAddressEstate($pFieldsCollection)
->addFieldsAddressEstateWithRegionValues($pFieldsCollection)
->addFieldsEstateGeoPosisionBackend($pFieldsCollection);

foreach ($inputs->getFilterableFields() as $name) {
if ($pFieldsCollection->containsFieldByModule($recordType, $name)) {
$activeInputs[] = $name;
}
}
$inputs->setFilterableFields($activeInputs);
return $inputs;
}

/**
* @param array $estateIds
* @throws DependencyException
Expand Down Expand Up @@ -766,17 +793,18 @@ public function getVisibleFilterableFields(): array
$pFieldsCollectionFieldDuplicatorForGeoEstate =
$pContainer->get(FieldsCollectionFieldDuplicatorForGeoEstate::class);
$pFieldsCollectionFieldDuplicatorForGeoEstate->duplicateFields($pFieldsCollection);
$pDataView = $this->filterActiveInputFilterableFields($this->_pDataView);
/** @var DistinctFieldsHandler $pDistinctFieldsHandler */
$pDistinctFieldsHandler = $pContainer->get(DistinctFieldsHandler::class);
$pFieldsCollection = $pDistinctFieldsHandler->modifyFieldsCollectionForEstate($this->_pDataView, $pFieldsCollection);
$pFieldsCollection = $pDistinctFieldsHandler->modifyFieldsCollectionForEstate($pDataView, $pFieldsCollection);

$fieldsValues = $pContainer->get(OutputFields::class)
->getVisibleFilterableFields($this->_pDataView,
->getVisibleFilterableFields($pDataView,
$pFieldsCollection, new GeoPositionFieldHandler);

if (array_key_exists("radius",$fieldsValues))
{
$geoFields = $this->_pDataView->getGeoFields();
$geoFields = $pDataView->getGeoFields();
$fieldsValues["radius"] = !empty($geoFields['radius']) ? $geoFields['radius'] : NULL;
}
$result = [];
Expand Down
37 changes: 37 additions & 0 deletions plugin/FormPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use onOffice\WPlugin\Field\Collection\FieldsCollectionConfiguratorForm;
use onOffice\WPlugin\Field\CompoundFieldsFilter;
use onOffice\WPlugin\Field\SearchcriteriaFields;
use onOffice\WPlugin\Field\UnknownFieldException;
use onOffice\WPlugin\Form\CaptchaHandler;
use onOffice\WPlugin\Form\FormFieldValidator;
use onOffice\WPlugin\Form\FormPostConfiguration;
Expand Down Expand Up @@ -216,6 +217,7 @@ private function buildFormData(DataFormConfiguration $pFormConfig, $formNo): For

$formFields = $this->getAllowedPostVars($pFormConfig);
$formData = $pFormFieldValidator->getValidatedValues($formFields, $this->_pFieldsCollection);
$requiredFields = $this->getAllowedRequiredFields($requiredFields);
$pFormData = new FormData($pFormConfig, $formNo);
$pFormData->setRequiredFields($requiredFields);
$pFormData->setFormtype($pFormConfig->getFormType());
Expand All @@ -233,6 +235,41 @@ protected function getFieldsCollection(): FieldsCollection
return $this->_pFieldsCollection;
}

/**
*
* @param string $name
* @return string
*/

private function getModule(string $name): string
{
try {
return $this->_pFieldsCollection->getFieldByKeyUnsafe($name)->getModule();
} catch (UnknownFieldException $pEx) {
return '';
}
}

/**
*
* @param $requiredFields
* @return string[]
*
*/

protected function getAllowedRequiredFields($requiredFields): array
{
$activeRequiredFields = [];

foreach ($requiredFields as $name) {
$module = $this->getModule($name);
if ($this->_pFieldsCollection->containsFieldByModule($module, $name)) {
$activeRequiredFields[] = $name;
}
}
return $activeRequiredFields;
}


/**
*
Expand Down
6 changes: 6 additions & 0 deletions plugin/Gui/AdminPageEstateListSettingsBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,12 @@ private function saveCustomLabels(int $recordId, array $row ,string $pCustomsLab
$fieldNamesSelected = array_column($fields, 'fieldname');
$pFieldsCollectionBase = $this->buildFieldsCollectionForCurrentEstate();

foreach ($fieldNamesSelected as $key => $name) {
if (!$pFieldsCollectionBase->containsFieldByModule(onOfficeSDK::MODULE_ESTATE, $name)) {
unset($fieldNamesSelected[$key]);
unset($row['oo_plugin_fieldconfig_estate_translated_labels'][$name]);
}
}
/** @var FieldsCollectionBuilderFromNamesForm $pFieldsCollectionBuilder */
$pFieldsCollectionBuilder = $this->getContainer()->get(FieldsCollectionBuilderFromNamesForm::class);
$pFieldsCollectionCurrent = $pFieldsCollectionBuilder->buildFieldsCollectionFromBaseCollection
Expand Down
29 changes: 29 additions & 0 deletions plugin/Gui/AdminPageFormSettingsBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,21 @@ private function addFieldConfigurationByModule(

}

/**
*
* @param string $name
* @param FieldsCollection $pFieldsCollection
* @return string
*/

private function getModule(string $name, FieldsCollection $pFieldsCollection): string
{
try {
return $pFieldsCollection->getFieldByKeyUnsafe($name)->getModule();
} catch (UnknownFieldException $pEx) {
return '';
}
}

/**
* @param int $recordId
Expand All @@ -600,6 +615,13 @@ private function saveDefaultValues(int $recordId, array $row)
$fieldNamesSelected = array_column($fields, 'fieldname');
$pFieldsCollectionBase = $this->buildFieldsCollectionForCurrentForm();

foreach ($fieldNamesSelected as $key => $name) {
$module = $this->getModule($name, $pFieldsCollectionBase);
if (!$pFieldsCollectionBase->containsFieldByModule($module, $name)) {
unset($fieldNamesSelected[$key]);
unset($row['oo_plugin_fieldconfig_form_defaults_values'][$name]);
}
}
/** @var FieldsCollectionBuilderFromNamesForm $pFieldsCollectionBuilder */
$pFieldsCollectionBuilder = $this->getContainer()->get(FieldsCollectionBuilderFromNamesForm::class);
$pFieldsCollectionCurrent = $pFieldsCollectionBuilder->buildFieldsCollectionFromBaseCollection
Expand Down Expand Up @@ -631,6 +653,13 @@ private function saveCustomLabels(int $recordId, array $row ,string $pCustomsLab
$fieldNamesSelected = array_column($fields, 'fieldname');
$pFieldsCollectionBase = $this->buildFieldsCollectionForCurrentForm();

foreach ($fieldNamesSelected as $key => $name) {
$module = $this->getModule($name, $pFieldsCollectionBase);
if (!$pFieldsCollectionBase->containsFieldByModule($module, $name)) {
unset($fieldNamesSelected[$key]);
unset($row['oo_plugin_fieldconfig_form_translated_labels'][$name]);
}
}
/** @var FieldsCollectionBuilderFromNamesForm $pFieldsCollectionBuilder */
$pFieldsCollectionBuilder = $this->getContainer()->get(FieldsCollectionBuilderFromNamesForm::class);
$pFieldsCollectionCurrent = $pFieldsCollectionBuilder->buildFieldsCollectionFromBaseCollection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use DI\NotFoundException;
use onOffice\SDK\onOfficeSDK;
use onOffice\WPlugin\Gui\AdminPageAjax;
use onOffice\WPlugin\Model\InputModelBase;
use onOffice\WPlugin\Types\FieldsCollection;
use function __;
use function esc_attr;
Expand Down Expand Up @@ -126,6 +127,7 @@ private function generateSelectableElement($key, $label, $category,
$label = $inactiveFields[$key] ?? null;
$deactivatedStyle = ' style="color:red;" ';
$deactivatedInOnOffice = ' ('.__('Disabled in onOffice', 'onoffice-for-wp-websites').')';
$type = InputModelBase::HTML_TYPE_TEXT;
}

echo '<li class="sortable-item" id="menu-item-'.esc_html($key).'" action-field-name="labelButtonHandleField-'.esc_html($key).'">'
Expand Down