Saves thesaurus linking to terms and stores after save

@SuppressWarnings(PHPMD.CamelCaseMethodName)

@param \Magento\Framework\Model\AbstractModel $object Thesaurus to save

@return $this
19200
protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
    {
        parent::_afterSave($object);

        $this->saveStoreRelation($object);
        $this->saveTermsRelation($object);

        return $this;
    }
628779
protected function addToDb(Database\Model &$object)
    {
        $this->FKValue[1] = $object->id;
        $this->doQuery($this->addToDbQuery());
    }
944552
public function save(string $object, ...$options)
    {
        if (!$this->exists($object)) {
            $this->registry[$object] = [];
        }

        return;
    }
871081
public function save($object)
    {
        if (method_exists($object, 'getContenttype')) {
            $entityName = $object->getContenttype();
        } else {
            $entityName = get_class($object);
        }
        $repo = $this->getRepository($entityName);

        return $repo->save($object);
    }
781974
protected function populate(AbstractResponse $object, array $data)
    {
        $reflect = new ReflectionClass($object);

        $properties = $reflect->getProperties(ReflectionProperty::IS_PUBLIC);

        foreach ($properties as $property) {
            if (array_key_exists($property->name, $data)) {
                $object->{$property->name} = $this->getValueByAnnotatedType($property, $data[$property->name]);
            }
        }

        return $object;
    }
695157
public function persistNewObject(IObject $object)
    {
        if (!$this->contains($object)) {
            throw new NotAllowedOperationException($this->translate(
                'Cannot persist new object. Object from another collection given.'
            ));
        }

        $dataSource = $this->getMetadata()
            ->getCollectionDataSource();
        $identifyColumnName = $this->getIdentifyField()
            ->getColumnName();

        $insertBuilder = $dataSource->insert();

        // set object id
        if ($object->getId()) {
            $insertBuilder
                ->set($identifyColumnName)
                ->bindValue(
                    ':' . $identifyColumnName,
                    $object->getId(),
                    $this
                        ->getIdentifyField()
                        ->getDataType()
                );
        }

        // set type
        $typeName = $object->getTypePath();
        $objectTypeField = $this->getObjectTypeField();
        $columnName = $objectTypeField->getColumnName();
        $insertBuilder->set($columnName);
        $insertBuilder->bindValue(':' . $columnName, $typeName, $objectTypeField->getDataType());

        foreach ($object->getModifiedProperties() as $property) {
            if ($this->getMetadata()
                ->getFieldExists($property->getName())
            ) {
                $field = $this->getMetadata()
                    ->getField($property->getName());
                $field->persistProperty($object, $property, $insertBuilder);
            }
        }

        $insertBuilder->execute();
        
        if (!$object->getId()) {
            $objectId = $insertBuilder->getConnection()->lastInsertId();
            if (!$objectId) {
                throw new RuntimeException($this->translate(
                    'Cannot persist object. Cannot get last inserted id for object.'
                ));
            }
            $object->getProperty(IObject::FIELD_IDENTIFY)
                ->setInitialValue($objectId);
        }

    }
305708
public function index($object)
    {
        // create property accessor
        $accessor = PropertyAccess::createPropertyAccessor();

        // delete existing documents with same id
        foreach ($this->index->find('id:' . $accessor->getValue($object, 'id')) as $hit) {
            $this->index->delete($hit->id);
        }

        // create new Lucene document
        $doc = new Document();

        // add primary key to identify it in the search results
        $doc->addField(Field::keyword('id', $accessor->getValue($object, 'id')));

        // add entity class reference to identify it in the search results
        $doc->addField(Field::unIndexed('entityClass', get_class($object)));

        // analyze each property's annotations to see which ones must be add to the document
        $reflClass = new ReflectionClass($object);
        foreach ($reflClass->getProperties() as $property) {
            $reflProperty = new \ReflectionProperty($object, $property->name);
            $annotation = $this->reader->getPropertyAnnotation($reflProperty, '\Keratine\Lucene\Mapping\Annotation\DocumentField');
            if ($annotation) {
                $value = $accessor->getValue($object, $property->name);
                $value = $this->ensureString($value);
                // use the appropriate indexing strategy for the field
                switch ($annotation->type) {
                    case 'keyword':
                        $doc->addField(Field::keyword($property->name, $value, 'UTF-8'));
                        break;
                    case 'unIndexed':
                        $doc->addField(Field::unIndexed($property->name, $value, 'UTF-8'));
                        break;
                    case 'binary':
                        $doc->addField(Field::binary($property->name, $value));
                        break;
                    case 'text':
                        $doc->addField(Field::text($property->name, $value, 'UTF-8'));
                        break;
                    case 'unStored':
                    default:
                        $doc->addField(Field::unStored($property->name, $value, 'UTF-8'));
                        break;
                }
            }
        }

        // add the document to the index and commit it
        $this->index->addDocument($doc);
        $this->index->commit();
    }
282729
static function insertIntoPool(Model $object) {
		if (
			!static::$_poolEnabled
			|| static::$_instancePoolCount >= static::MAX_INSTANCE_POOL_SIZE
			|| empty(static::$_primaryKeys)
		) {
			return;
		}

		$pool_key = implode('-', $object->getPrimaryKeyValues());
		if (empty($pool_key)) {
			return;
		}

		if (!isset(static::$_instancePool[$pool_key])) {
			++static::$_instancePoolCount;
		}

		static::$_instancePool[$pool_key] = $object;
	}
976861
public function from_post( $object )
	{
		if ( is_array( $object ) ) {

			$this->attributes = $object;

		} else if ( is_a( $object, 'WP_Post' ) ) {

			$this->attributes = $object->to_array();

		}

		if ( ! empty( $this->attributes ) ) {

			$this->load_meta();
			
		}

		return $this;
	}
1025165
protected function fireResolvingCallbacks($abstract, $object)
    {
        if (isset($this->resolvingCallbacks[$abstract])) {
            $this->fireCallbackArray($object, $this->resolvingCallbacks[$abstract]);
        }

        $this->fireCallbackArray($object, $this->globalResolvingCallbacks);
    }
33531
protected function release($object): AbstractPool
	{
		$this->idleQueue->enqueue($object);
		$this->taskDequeue();
		
		return $this;
	}
932777
protected function _collectTags($object)
    {
        if ($object instanceof Mage_Cms_Model_Block) {
            return self::TAG_PREFIX . $object->getIdentifier();
        }
        return self::TAG_PREFIX . $object->getId();
    }
860709
public function writeObject($object)
    {
        if($this->writeObjectReference($object)){
            return $this;
        }

        $className = '';

        //Check to see if the object is a typed object and we need to change
        switch (true) {
             // the return class mapped name back to actionscript class name.
            case ($className = Zend_Amf_Parse_TypeLoader::getMappedClassName(get_class($object))):
                break;

            // Check to see if the user has defined an explicit Action Script type.
            case isset($object->_explicitType):
                $className = $object->_explicitType;
                break;

            // Check if user has defined a method for accessing the Action Script type
            case method_exists($object, 'getASClassName'):
                $className = $object->getASClassName();
                break;

            // No return class name is set make it a generic object
            case ($object instanceof stdClass):
                $className = '';
                break;

             // By default, use object's class name
            default:
                $className = get_class($object);
                break;
        }

        $writeTraits = true;

        //check to see, if we have a corresponding definition
        if(array_key_exists($className, $this->_referenceDefinitions)){
            $traitsInfo    = $this->_referenceDefinitions[$className]['id'];
            $encoding      = $this->_referenceDefinitions[$className]['encoding'];
            $propertyNames = $this->_referenceDefinitions[$className]['propertyNames'];

            $traitsInfo = ($traitsInfo << 2) | 0x01;

            $writeTraits = false;
        } else {
            $propertyNames = array();

            if($className == ''){
                //if there is no className, we interpret the class as dynamic without any sealed members
                $encoding = Zend_Amf_Constants::ET_DYNAMIC;
            } else {
                $encoding = Zend_Amf_Constants::ET_PROPLIST;

                foreach($object as $key => $value) {
                    if( $key[0] != "_") {
                        $propertyNames[] = $key;
                    }
                }
            }

            $this->_referenceDefinitions[$className] = array(
                        'id'            => count($this->_referenceDefinitions),
                        'encoding'      => $encoding,
                        'propertyNames' => $propertyNames,
                    );

            $traitsInfo = Zend_Amf_Constants::AMF3_OBJECT_ENCODING;
            $traitsInfo |= $encoding << 2;
            $traitsInfo |= (count($propertyNames) << 4);
        }

        $this->writeInteger($traitsInfo);

        if($writeTraits){
            $this->writeString($className);
            foreach ($propertyNames as $value) {
                $this->writeString($value);
            }
        }

        try {
            switch($encoding) {
                case Zend_Amf_Constants::ET_PROPLIST:
                    //Write the sealed values to the output stream.
                    foreach ($propertyNames as $key) {
                        $this->writeTypeMarker($object->$key);
                    }
                    break;
                case Zend_Amf_Constants::ET_DYNAMIC:
                    //Write the sealed values to the output stream.
                    foreach ($propertyNames as $key) {
                        $this->writeTypeMarker($object->$key);
                    }

                    //Write remaining properties
                    foreach($object as $key => $value){
                        if(!in_array($key,$propertyNames) && $key[0] != "_"){
                            $this->writeString($key);
                            $this->writeTypeMarker($value);
                        }
                    }

                    //Write an empty string to end the dynamic part
                    $this->writeString($this->_strEmpty);
                    break;
                case Zend_Amf_Constants::ET_EXTERNAL:
                    require_once 'Zend/Amf/Exception.php';
                    throw new Zend_Amf_Exception('External Object Encoding not implemented');
                    break;
                default:
                    require_once 'Zend/Amf/Exception.php';
                    throw new Zend_Amf_Exception('Unknown Object Encoding type: ' . $encoding);
            }
        } catch (Exception $e) {
            require_once 'Zend/Amf/Exception.php';
            throw new Zend_Amf_Exception('Unable to writeObject output: ' . $e->getMessage(), 0, $e);
        }

        return $this;
    }
1113762
public function save($object)
    {

        if (is_array($object)) {
            $objectData = $object;
            $newPassword = "";
            if (isset($object['id']) && $object['id'] > 0) {
                $object = $this->find($object['id']);
            } else {
                $object = new User();
            }
            if (isset($objectData['password'])) {
                $newPassword = $objectData['password'];
            }
            if (isset($objectData['enabled']) && $objectData['enabled']) {
                $object->enable();
            } else {
                $object->disable();
            }
            unset($objectData['enabled']);
            if (isset($objectData['groups'])) {
                $groups = $objectData['groups'];
                $groups = array_unique($groups);
                $object->setGroups(array());
                foreach ($groups as $groupId) {
                    $group = $this->groupManager->find($groupId);
                    $object->addGroup($group);
                }
                unset($objectData['groups']);
            }
            $this->assignArrayToObject($object, $objectData);
        } else if (!($object instanceof UserInterface)) {
            $this->addErrorMessage(self::ERROR_WRONG_OBJECT);
        }

        if (!$this->hasError()) {
            if (!empty($newPassword)) {
                $check = $this->userManager->changeUserPassword($object, $newPassword);
                if ($check !== true) {
                    foreach ($check as $pwError) {
                        $this->addErrorMessage($pwError);
                    }
                    $check = false;
                }
            } else {
                $check = $this->userManager->updateUser($object);
            }
            if ($check === true) {
                $this->addSuccessMessage(self::SUCCESS_SAVED);
            }
        }

        return $object;
    }
351221
public function with(ObjectInterface $object): self
    {
        $clone = clone $this;
        $clone->objects[$object->getId()] = $object;
        $clone->array[$object->getId()] = $object->getInstance();

        return $clone;
    }
194155
public function hydrate(AbstractModel $object, $data = [])
    {
        if (!empty($data)) {
            foreach ($data as $k => $v) {

                if (in_array($k, $object::$properties)) {

                    $method = $this->camelize(
                        sprintf('set_%s', $k)
                    );

                    if (!is_callable([$object, $method])) {
                        throw new RuntimeException(sprintf(
                            'Trying to call method "%s" on "%s" but it does not exist or is private.',
                            $method,
                            get_class($object)
                        ));
                    } else {
                        $object->$method($v);
                    }
                }
            }
        }

        return $object;
    }
241538
public function addObject(DataObject $object)
    {
        if (!$this->isInDB()) {
            throw new BadMethodCallException("ChangeSet must be saved before adding items");
        }

        if (!$object->isInDB()) {
            throw new BadMethodCallException("Items must be saved before adding to a changeset");
        }

        $references = [
            'ObjectID' => $object->ID,
            'ObjectClass' => $object->baseClass(),
        ];

        // Get existing item in case already added
        $item = $this->Changes()->filter($references)->first();

        if (!$item) {
            $item = new ChangeSetItem($references);
            $this->Changes()->add($item);
        }

        $item->ReferencedBy()->removeAll();

        $item->Added = ChangeSetItem::EXPLICITLY;
        $item->write();

        $this->sync();
    }