Skip to content

Instantly share code, notes, and snippets.

@dbu
dbu / _README.md
Last active November 5, 2018 17:02
Elasticsearch: Find all documents that have invalid entries in an array

We had a problem where invalid data got stored in elasticsearch. An array of objects had some objects placed in it that are missing a mandatory field. After fixing the mistake, we wanted to update all offending entires. For this, we need to get the IDs of affected items.

The "obvious" query would be _exists_:general_information AND !(_exists_:general_information.value). But as soon as there is any array element with a value, the second condition will consider the value existing. If there are any valid entries in the array, the query will not work as expected.

The solution we found was to use an ES script that loops over the elements in the source document and returns 1 if it finds one that has no data. To our positive surprise, running this on an index with over 1M entries only took a couple of seconds. Definitely not something for a routine query, but an acceptable time for a one-off query to fix a problem.

@dbu
dbu / README.md
Last active October 2, 2018 11:57
Convert NelmioApiDocBundle annotations to Swagger PHP

A Symfony command to convert from NelmioApiDocBundle annotations to Swagger-PHP annotations.

This code is provided as is. Make sure to have your code committed to version control before running the command. Check if things work out and if not, use version control to reset the automated changes and fix the command.

@dbu
dbu / Kernel.php
Last active September 12, 2018 09:25
Load environment specific configuration in symfony 4 kernel
<?php
namespace App;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
use Symfony\Component\Routing\RouteCollectionBuilder;
@dbu
dbu / Dockerfile
Created August 7, 2018 06:15
why does the anchor folder not exist in the docker image?
FROM mprasil/dokuwiki
RUN apt-get update && \
apt-get install -y unzip curl && \
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN curl -O -L "https://github.com/turnermm/ckgedit/archive/master.zip" && \
unzip master.zip -d /dokuwiki/lib/plugins/ && \
mv /dokuwiki/lib/plugins/ckgedit-master /dokuwiki/lib/plugins/ckgedit && \
rm -f master.zip
RUN curl -O -L "https://trello-attachments.s3.amazonaws.com/5af4815352fa15728c62aaae/5afe9c8a66d239ee43a6f068/92c13557957b1d6893779951e94ef181/anchor.zip"
RUN unzip anchor.zip -d /dokuwiki/lib/plugins
@dbu
dbu / ConfluenceUserProvider.php
Created April 23, 2013 07:05
confluence soap user provider
<?php
namespace Acme\UserBundle\Security\User;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Core\User\UserInterface as SecurityUserInterface;
use Symfony\Component\Validator\Validator;
class ConfluenceUserProvider implements UserProviderInterface
@dbu
dbu / SynchronizeTranslationsCommand.php
Created December 5, 2012 17:21
Xliff translation updated
<?php
namespace Liip\CoreBundle\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Translation\Loader\LoaderInterface;
use Symfony\Component\Finder\Finder;
@dbu
dbu / Vagrantfile
Created November 13, 2012 09:26
vagrant setup
# -*- mode: ruby -*-
# vi: set ft=ruby :
this_dir = File.dirname(__FILE__) + "/"
require this_dir + "vagrant/hostmaster.rb"
Vagrant::Config.run do |config|
# define some colors for our output
def colorize(text, color_code) "#{color_code}#{text}\033[0m" end
@dbu
dbu / ImageType.php
Created March 12, 2013 11:03
i needed a form type that determines based on the bound data if it should be required or not (to make file upload required if we create a new entity, but optional when editing the entity with the file. as this happens in a embedded sonata, i have no way of knowing the actual data when creating the form in the form builder. this is what i came up…
<?php
class ImageType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
if ($options['required_auto'] && ! $options['required']) {
$builder->addEventListener(\Symfony\Component\Form\FormEvents::PRE_SET_DATA, array($this, 'determineRequired'));
}
@dbu
dbu / FOS.UserBundle.Model.User.dcm.xml
Last active December 1, 2016 19:54
FOSUserBundle PHPCR-ODM binding
<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/phpcr-odm/phpcr-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/phpcr-odm/phpcr-mapping
https://github.com/doctrine/phpcr-odm/raw/master/doctrine-phpcr-odm-mapping.xsd">
<mapped-superclass name="FOS\UserBundle\Model\User">
<nodename name="usernameCanonical" />
use League\Flysystem\Util;
public function read($path)
{
$path = Util::normalizePath($path);
if (! ($object = $this->flysystem->getAdapter()->read($path))) {
return false;
}