I can not persist the data in the Bank

4

I think I'm doing something wrong in this class because it's the only one on my system that is not persisting in the database.

What am I forgetting to make it work? The incluir() method? If I run a var_dump($log) , before calling persist($log) , the result is a variable with all the required data.

And worst of all, it does not make any mistakes either.

Log.php class

namespace JN\Entity;
use Doctrine\ORM\Mapping as ORM;
/** 
* @ORM\Entity
* @ORM\Table(name="logs")
* @ORM\HasLifecycleCallbacks
*/
class Log {
/**
 * @ORM\Id
 * @ORM\Column(type="integer")
 * @ORM\GeneratedValue
 */
private $id;

/**
 * @ORM\Column(type="datetime")
 */
private $data;

/**
 * @ORM\Column(type="string", length=100)
 */
private $tabela;

/**
 * @ORM\Column(type="integer")
 */
private $id_usuario;

/**
 * @ORM\Column(type="string", length=200)
 */
private $usuario;

/**
 * @ORM\Column(type="integer", nullable=true)
 */
private $id_empresa;

/**
 * @ORM\Column(type="string", length=200, nullable=true)
 */
private $empresa;

/**
 * @ORM\Column(type="string", length=20)
 */
private $ip;

/**
 * @ORM\Column(type="string", length=100)
 */
private $evento;

/**
 * @ORM\Column(type="text")
 */
private $sql;

/**
 * @ORM\Column(type="text", nullable=true)
 */
private $valores_antigos;

/**
 * @ORM\Column(type="text", nullable=true)
 */
private $valores_novos;

/**
 * @ORM\Column(type="datetime")
 */
private $created_at;

/**
 * @ORM\Column(type="datetime")
 */
private $updated_at;

/*--------------------------Filters --------------------------------------- */
/**
 *
 * @ORM\PrePersist
 * @ORM\PreUpdate
 */
public function updatedTimestamps()
{
    $this->updated_at =new \DateTime('now');

    if ($this->created_at == null) {
        $this->created_at=new \DateTime('now');
    }
}


/*--------------------------Constructor --------------------------------------- */

/*--------------------------Relations --------------------------------------- */

/*--------------------------Gets and Sets --------------------------------------- */
/**
 * @return mixed
 */
public function getId()
{
    return $this->id;
}

/**
 * @return mixed
 */
public function getData()
{
    return $this->data;
}

/**
 * @param mixed $data
 */
public function setData($data)
{
    $this->data = $data;
}

/**
 * @return mixed
 */
public function getTabela()
{
    return $this->tabela;
}

/**
 * @param mixed $tabela
 */
public function setTabela($tabela)
{
    $this->tabela = $tabela;
}

/**
 * @return mixed
 */
public function getIdUsuario()
{
    return $this->id_usuario;
}

/**
 * @param mixed $id_usuario
 */
public function setIdUsuario($id_usuario)
{
    $this->id_usuario = $id_usuario;
}

/**
 * @return mixed
 */
public function getUsuario()
{
    return $this->usuario;
}

/**
 * @param mixed $usuario
 */
public function setUsuario($usuario)
{
    $this->usuario = $usuario;
}

/**
 * @return mixed
 */
public function getIdEmpresa()
{
    return $this->id_empresa;
}

/**
 * @param mixed $id_empresa
 */
public function setIdEmpresa($id_empresa)
{
    $this->id_empresa = $id_empresa;
}

/**
 * @return mixed
 */
public function getEmpresa()
{
    return $this->empresa;
}

/**
 * @param mixed $empresa
 */
public function setEmpresa($empresa)
{
    $this->empresa = $empresa;
}

/**
 * @return mixed
 */
public function getIp()
{
    return $this->ip;
}

/**
 * @param mixed $ip
 */
public function setIp($ip)
{
    $this->ip = $ip;
}

/**
 * @return mixed
 */
public function getEvento()
{
    return $this->evento;
}

/**
 * @param mixed $evento
 */
public function setEvento($evento)
{
    $this->evento = $evento;
}

/**
 * @return mixed
 */
public function getSql()
{
    return $this->sql;
}

/**
 * @param mixed $sql
 */
public function setSql($sql)
{
    $this->sql = $sql;
}

/**
 * @return mixed
 */
public function getValoresAntigos()
{
    return $this->valores_antigos;
}

/**
 * @param mixed $valores_antigos
 */
public function setValoresAntigos($valores_antigos)
{
    $this->valores_antigos = $valores_antigos;
}

/**
 * @return mixed
 */
public function getValoresNovos()
{
    return $this->valores_novos;
}

/**
 * @param mixed $valores_novos
 */
public function setValoresNovos($valores_novos)
{
    $this->valores_novos = $valores_novos;
}

/**
 * @return mixed
 */
public function getCreatedAt()
{
    return $this->created_at;
}

/**
 * @return mixed
 */
public function getUpdatedAt()
{
    return $this->updated_at;
}
}

LogService.php class

namespace JN\Entity;
use Doctrine\ORM\EntityManager;
class LogService {

private $em;
private $app;

public function __construct(EntityManager $em, $app)
{
    $this->em=$em;
    $this->app=$app;
}

public function incluir($sesion=null,$valoresNovos=null)
{
    try{
        $log = new Log();
        $log->setEmpresa('');
        $log->setIdEmpresa(0);
        $log->setIdUsuario(0);
        $log->setUsuario('');
        $log->setData(new \DateTime('now'));
        $log->setIp($_SERVER["REMOTE_ADDR"]);
        $log->setEvento('Inclusão');
        $log->setTabela($sesion['tabela']);
        $log->setSql($sesion['sql']);
        $log->setValoresAntigos('');
        $log->setValoresNovos($valoresNovos);
        $this->em->persist($log);
        $this->em->flush();
        return $log;
    }catch (\Exception $ex){
        $this->app->abort(406, 'Erro: ('.$ex->getCode().') '.$ex->getMessage());
        //return ['sucesso'=>false, 'Erro: '=>$ex->getCode().': '.$ex->getMessage()];
    }
}
    
asked by anonymous 03.02.2015 / 22:08

1 answer

3

I found the problem. Only to be recorded in the records. The problem was that I had a column named SQL and Data, these 2 words are reserved and could not be used. After a lot of trying, he decided to change them.

Thank you all for the help.

    
04.02.2015 / 16:17