Update the block.

@param Request $request
@param Model   $block

@return Response
508354
public function update(BlockRequest $request, Block $block)
    {
        try {
            $attributes = $request->all();

            $block->update($attributes);
            return $this->response->message(trans('messages.success.updated', ['Module' => trans('block::block.name')]))
                ->code(204)
                ->status('success')
                ->url(guard_url('block/block/' . $block->getRouteKey()))
                ->redirect();
        } catch (Exception $e) {
            return $this->response->message($e->getMessage())
                ->code(400)
                ->status('error')
                ->url(guard_url('block/block/' . $block->getRouteKey()))
                ->redirect();
        }

    }
813346
public function validateBlockUpdateStruct(Block $block, BlockUpdateStruct $blockUpdateStruct): void
    {
        $this->validate(
            $blockUpdateStruct,
            [
                new BlockUpdateStructConstraint(
                    [
                        'payload' => $block,
                    ]
                ),
            ]
        );

        $this->validate(
            $blockUpdateStruct,
            new ConfigAwareStructConstraint(
                [
                    'payload' => $block->getDefinition(),
                    'allowMissingFields' => true,
                ]
            )
        );
    }
1221526
public function update(Request $request, $id)
    {
        $this->validate($request, ['name' => 'required']);

        $role = Role::findOrFail($id);
        $role->update($request->all());
        $role->permissions()->detach();

        if ($request->has('permissions')) {
            foreach ($request->permissions as $permission_name) {
                $permission = Permission::whereName($permission_name)->first();
                $role->givePermissionTo($permission);
            }
        }

        return redirect('admin/roles')->with('flash_message', 'Role updated!');
    }
749354
protected function updateBlocks(Database $db)
    {
        $this->write(' + Updating block documents');

        $this->write(' + updating medias in tinyMce attributes');

        $this->checkExecute($db->execute(
            $this->getJSFunctions() . '

            db.block.find({}).snapshot().forEach(function(block) {
                var updated = false;

                for (var attributeName in block.attributes) {
                    if (block.attributes.hasOwnProperty(attributeName) && (typeof block.attributes[attributeName] == "string")) {
                        var pattern = /\[media=([^\]\{]+)\]([^\]]+)\[\/media\]|\[media=\{"format":"([^"]+)"\}\]([^\]]+)\[\/media\]/g;
                        var matches = pattern.execAll(block.attributes[attributeName]);

                        for (var i = 0; i < matches.length; i++) {
                            var mediaId = getMediaIdFromMatch(matches[i]);
                            var format = getMediaFormatFromMatch(matches[i]);
                            block.attributes[attributeName] = updateAttribute(block.attributes[attributeName], mediaId, format, getMediaAlt(mediaId, block.language));
                            updated = true;
                        }
                    }
                }

                if (updated) {
                    db.block.update({_id: block._id}, block);
                }
            });
        '));

        $this->write(' + updating medias in block attributes');

        $configMediaFieldType = $this->container->getParameter('open_orchestra_migration.media_configuration');

        $this->checkExecute($db->execute(
            $this->getJSFunctions() . '

            var blockMediaFieldAttribute = '.json_encode($configMediaFieldType['block_media_field_attribute']).';
            db.block.find({}).snapshot().forEach(function(block) {
                var updated = false;
                for (var attributeName in block.attributes) {
                    if (
                        block.attributes.hasOwnProperty(attributeName) &&
                        blockMediaFieldAttribute.indexOf(attributeName) > -1
                    ) {
                        var alt = "";
                        if (
                            null !== block.attributes[attributeName].id &
                            "" !== block.attributes[attributeName].id
                        ) {
                           alt = getMediaAlt(block.attributes[attributeName].id, block.language);
                        }
                        block.attributes[attributeName].alt = alt;
                        block.attributes[attributeName].legend = "";
                        updated = true;
                    }
                }

                if (updated) {
                    db.block.update({_id: block._id}, block);
                }
            });
        '));
    }
1070131
public function update(Request $request)
    {
        Voyager::canOrFail('browse_database');

        $table = json_decode($request->table, true);

        try {
            DatabaseUpdater::update($table);
            // TODO: synch BREAD with Table
            // $this->cleanOldAndCreateNew($request->original_name, $request->name);
        } catch (Exception $e) {
            return back()->with($this->alertException($e))->withInput();
        }

        return redirect()
               ->route('voyager.database.edit', $table['name'])
               ->with($this->alertSuccess("Successfully updated {$table['name']} table"));
    }
592462
public function blockAction(Request $request, $pageId, $blockName)
    {
        $em = $this->getDoctrine()->getManager();

        /* get current locale */
        $locale = $request->getLocale();
        
        $entity = $em->getRepository('AmulenPageBundle:Block')->findOneBy(array('page' => $pageId, 'name' => $blockName, "lang" => $locale));
        $content = "";
        if ($entity) {
            $content = $entity->getContent();
        }
        return array(
            'content' => $content
        );
    }
922482
public function layoutAction(Request $request)
    {
        $block = $this->findBlockByRequest($request);

        $data = $request->request->get('data', []);

        try {
            $this->getEditor()->getLayoutAdapter()->updateBlockLayout($block, $data);
        } catch (EditorExceptionInterface $e) {
            return $this->handleException($e);
        }

        $this->validate($block);
        $this->persist($block);

        $data = [
            'blocks' => [$this->getViewBuilder()->buildBlock($block)],
        ];

        return $this->buildResponse($data, self::SERIALIZE_LAYOUT);
    }
645595
public function updateBlockTranslation(Block $block, string $locale): void
    {
        $query = $this->connection->createQueryBuilder();
        $query
            ->update('ngbm_block_translation')
            ->set('parameters', ':parameters')
            ->where(
                $query->expr()->andX(
                    $query->expr()->eq('block_id', ':block_id'),
                    $query->expr()->eq('locale', ':locale')
                )
            )
            ->setParameter('block_id', $block->id, Type::INTEGER)
            ->setParameter('locale', $locale, Type::STRING)
            ->setParameter('parameters', $block->parameters[$locale], Type::JSON_ARRAY);

        $this->applyStatusCondition($query, $block->status);

        $query->execute();
    }
1368746
public function update(Request $request, $id)
    {
        /** @noinspection PhpUndefinedMethodInspection */
        $request->validate(['name' => 'required|max:128']);
        /** @noinspection PhpUndefinedMethodInspection */
        $location = Location::findOrFail($id);
        $location->name = $request->name;
        $this->authorize('update', $location);
        /** @noinspection PhpUndefinedMethodInspection */
        $location->save();
        return fractal($location, new LocationTransformer())
            ->withResourceName('location')
            ->respond();

    }
430596
public function update(Request $request)
    {
        $permission = Permission::findOrFail($request->permission_id);

        $permission->name = $request->name;

        $permission->update();

        return redirect('scaffold-permissions');
    }
814956
protected function _setBlock($block)
    {
        if ($block !== null && !($block instanceof BlockInterface)) {
            throw $this->_createInvalidArgumentException(
                $this->__('Invalid block'),
                null,
                null,
                $block
            );
        }

        $this->block = $block;
    }
138566
public function updateTreeAction(Request $request)
    {
        /** @var Request $request */
        $nodes = $request->get('nodes') ? $request->get('nodes') : [];

        $admin = $this->get('networking_init_cms.admin.tag');

        $validator = $this->get('validator');
        try {
            foreach ($nodes as $node) {
                if (!$node['id']) {
                    continue;
                }
                /** @var $tag Tag */
                $tag = $admin->getObject($node['id']);
                if ($node['parent_id']) {
                    $parent = $admin->getObject($node['parent_id']);
                    $tag->setParent($parent);
                } else {
                    $tag->setParent(null);
                }

                $tag->setLevel($node['depth'] + 1);

                $errors = $validator->validate($tag);
                if (count($errors) > 0) {
                    throw new ValidatorException();
                }

                $this->admin->update($tag);
            }

            $response = ['status' => 'success', 'message' => $this->admin->trans('info.tag_sorted')];
        } catch (\Exception $e) {
            $response = ['status' => 'error', 'message' => $this->admin->trans('info.tag_sorted_error')];
        }

        return $this->renderJson($response);
    }
914092
public function update(User $user, Block $block)
    {
        if ($block->author->id === $user->id) {
            return true;
        }
        return $user->hasPermission('block-update');
    }
1096394
public function changeTypeAction(Request $request)
    {
        $block = $this->findBlockByRequest($request);
        $type = $request->request->get('type', null);
        $removed = [];

        if ($type != $block->getType()) {
            foreach ($this->getViewBuilder()->buildBlock($block)->widgets as $widget) {
                $removed[] = $widget->getAttributes()->getId();
            }

            try {
                $this->getEditor()->getBlockManager()->changeType($block, $type);
            } catch (EditorExceptionInterface $e) {
                return $this->handleException($e);
            }

            $this->validate($block);
            $this->persist($block);
        }

        $data = [
            'removed' => $removed,
            'blocks'  => [
                $this->getViewBuilder()->buildBlock($block),
            ],
        ];

        return $this->buildResponse($data, self::SERIALIZE_CONTENT);
    }
65828
public function publishSharedAction(Request $request)
    {
        $this->getDoctrine()->getManager()->getFilters()->disable('draft');

        /** @var BlockManager $manager */
        $manager  = $this->get('opifer.content.block_manager');
        $response = new JsonResponse;
        $id       = (int) $request->request->get('id');

        try {
            $block = $manager->find($id, true);
            $block->setUpdatedAt(new \DateTime());
            $manager->publish($block);

            if ($block instanceof CompositeBlock) {
                $manager->publish($manager->findDescendants($block));
            }

            $response->setStatusCode(200);
            $response->setData(['state' => 'published']);
        } catch (\Exception $e) {
            $response->setStatusCode(500);
            $response->setData(['error' => $e->getMessage() . $e->getTraceAsString()]);
        }

        return $response;
    }
12381
public function update($id,Request $request)
    {
        $email = $this->emails->update( $request->all() );

        alert()->success('Email mis à jour');

        return redirect('build/liste/'.$email->list_id);
    }
78190
public function editBlockAction(Request $request, $id, $version = 0)
    {
        $this->getDoctrine()->getManager()->getFilters()->disable('draftversion');

        /** @var BlockManager $manager */
        $manager = $this->get('opifer.content.block_manager');
        $version = $manager->getNewVersion($manager->find($id));

//        if ((int) $rootVersion !== $newVersion) {
//            throw new \Exception("Only new versions can be editted. New version is {$newVersion} while you requested {$rootVersion}");
//        }

        $block = $manager->find($id, $version);

        /** @var BlockServiceInterface $service */
        $service = $manager->getService($block);
        $block->setRootVersion($version);

        $updatePreview = false; // signals parent window preview from iframe to update preview

        $service->preFormSubmit($block);

        $form = $this->createForm(new BlockAdapterFormType($service), $block);
        $form->handleRequest($request);

        if ($form->isValid()) {

            $service->postFormSubmit($form, $block);

            $manager->save($block);
            $updatePreview = true;
        }

        return $this->render($service->getEditView(), [
            'block_service' => $service,
            'block' => $block,
            'form' => $form->createView(),
            'update_preview' => $updatePreview
        ]);
    }