/** * @param ObjectManager $manager */ public function load(ObjectManager $manager) { $fieldGroups['lead'] = FieldModel::$coreFields; $fieldGroups['company'] = FieldModel::$coreCompanyFields; $translator = $this->container->get('translator'); $indexesToAdd = []; foreach ($fieldGroups as $object => $fields) { if ($object == 'company') { /** @var ColumnSchemaHelper $companiesSchema */ $schema = $this->container->get('mautic.schema.helper.factory')->getSchemaHelper('column', 'companies'); } else { /** @var ColumnSchemaHelper $companiesSchema */ $schema = $this->container->get('mautic.schema.helper.factory')->getSchemaHelper('column', 'leads'); } $order = 1; foreach ($fields as $alias => $field) { $type = isset($field['type']) ? $field['type'] : 'text'; $entity = new LeadField(); $entity->setLabel($translator->trans('mautic.lead.field.' . $alias, [], 'fixtures')); $entity->setGroup(isset($field['group']) ? $field['group'] : 'core'); $entity->setOrder($order); $entity->setAlias($alias); $entity->setIsRequired(isset($field['required']) ? $field['required'] : false); $entity->setType($type); $entity->setObject($field['object']); $entity->setIsUniqueIdentifer(!empty($field['unique'])); $entity->setProperties(isset($field['properties']) ? $field['properties'] : []); $entity->setIsFixed(!empty($field['fixed'])); $entity->setIsListable(!empty($field['listable'])); $entity->setIsShortVisible(!empty($field['short'])); $manager->persist($entity); $manager->flush(); $schema->addColumn(FieldModel::getSchemaDefinition($alias, $type, $entity->getIsUniqueIdentifier())); $indexesToAdd[$object][] = $alias; $this->addReference('leadfield-' . $alias, $entity); ++$order; } $schema->executeChanges(); } foreach ($indexesToAdd as $object => $indexes) { if ($object == 'company') { /** @var IndexSchemaHelper $indexHelper */ $indexHelper = $this->container->get('mautic.schema.helper.factory')->getSchemaHelper('index', 'companies'); } else { /** @var IndexSchemaHelper $indexHelper */ $indexHelper = $this->container->get('mautic.schema.helper.factory')->getSchemaHelper('index', 'leads'); } foreach ($indexes as $name) { $type = isset($fields[$name]['type']) ? $fields[$name]['type'] : 'text'; if ('textarea' != $type) { $indexHelper->addIndex([$name], $name . '_search'); } } if ($object == 'lead') { // Add an attribution index $indexHelper->addIndex(['attribution', 'attribution_date'], 'contact_attribution'); } else { $indexHelper->addIndex(['companyname', 'companyemail'], 'company_filter'); $indexHelper->addIndex(['companyname', 'companycity', 'companycountry', 'companystate'], 'company_match'); } $indexHelper->executeChanges(); } }
/** * {@inheritDoc} */ public function setIsRequired($isRequired) { $this->__initializer__ && $this->__initializer__->__invoke($this, 'setIsRequired', array($isRequired)); return parent::setIsRequired($isRequired); }