floriansemm / SolrBundle

Solr-Integration into Symfony and Doctrine2
http://floriansemm.github.io/SolrBundle
MIT License
123 stars 73 forks source link

No repository found #155

Closed Cypaubr closed 7 years ago

Cypaubr commented 7 years ago

Hi, I try to index my users but I have a recurrent error :

Indexing: OneDayBundle\Entity\User
No repository found for "OneDayBundle\Entity\User", check your input

Here is my User entity class :

<?php

namespace OneDayBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
use FS\SolrBundle\Doctrine\Annotation as Solr;

/**
 * User
 *
 * @Solr\Document(index="1day-users", repository="OneDayBundle\SolrRepository\UserRepository")
 *
 * @ORM\Table(name="user")
 * @ORM\Entity(repositoryClass="OneDayBundle\Repository\UserRepository")
 *
 * @author Cyprien A.
 * @version 1.2
 */
class User implements UserInterface, \Serializable
{
    public static $ROLE_USER = 'ROLE_USER'; //par défaut
    public static $ROLE_ADMIN = 'ROLE_ADMIN';

    public static $DEFAULT_AUTH = 0;
    public static $SMS_AUTH = 1;
    public static $GA_AUTH = 2;

    /**
     * @var int
     *
     * @Solr\Id
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var string
     *
     * @Solr\Field(type="string")
     *
     * @ORM\Column(name="email", type="string", length=255, unique=true)
     */
    private $email;

    /**
     * @var string
     *
     * @Solr\Field(type="string")
     *
     * @ORM\Column(name="password", type="string", length=255)
     */
    private $password;

    /**
     * @var string
     *
     * @Solr\Field(type="string")
     *
     * @ORM\Column(name="salt", type="string", length=255)
     */
    private $salt;

    /**
     * @var \DateTime
     *
     * @Solr\Field(type="date", getter="format('Y-m-d\TH:i:s.z\Z')")
     *
     * @ORM\Column(name="registered", type="datetime")
     */
    private $registered;

    /**
     * @var \DateTime
     *
     * @Solr\Field(type="date", getter="format('Y-m-d\TH:i:s.z\Z')")
     *
     * @ORM\Column(name="lastConnect", type="datetime", nullable=true)
     */
    private $lastConnect;

    /**
     * @var \boolean
     *
     * @Solr\Field(type="boolean")
     *
     * @ORM\Column(name="validated", type="boolean", nullable=false)
     */
    private $validated;

    /**
     * @var \String
     *
     * @Solr\Field(type="string")
     *
     * @ORM\Column(name="role", type="string", nullable=false)
     */
    private $role;

    /**
     * @var \int
     *
     * @Solr\Field(type="integer")
     *
     * @ORM\Column(name="authMode", type="integer", nullable=false)
     */
    private $authMode;

    /**
     * @var \boolean
     *
     * @Solr\Field(type="boolean")
     *
     * @ORM\Column(name="isDev", type="boolean", nullable=false)
     */
    private $isDev;

    /**
     * @var \boolean
     *
     * @Solr\Field(type="boolean")
     *
     * @ORM\Column(name="isAdvertiser", type="boolean", nullable=false)
     */
    private $isAdvertiser;

    /**
     * @var \String
     *
     * @Solr\Field(type="string")
     *
     * @ORM\Column(name="deviceToken", type="string", length=250)
     */
    private $deviceToken;

    /**
     * Get id
     *
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set email
     *
     * @param string $email
     *
     * @return User
     */
    public function setEmail($email)
    {
        $this->email = $email;

        return $this;
    }

    /**
     * Get email
     *
     * @return string
     */
    public function getEmail()
    {
        return $this->email;
    }

    /**
     * Set password
     *
     * @param string $password
     *
     * @return User
     */
    public function setPassword($password)
    {
        $this->password = $password;

        return $this;
    }

    /**
     * Set salt
     *
     * @param string $salt
     *
     * @return User
     */
    public function setSalt($salt)
    {
        $this->salt = $salt;

        return $this;
    }

    /**
     * Get password
     *
     * @return string
     */
    public function getPassword()
    {
        return $this->password;
    }

    /**
     * Get salt
     *
     * @return string
     */
    public function getSalt()
    {
        return $this->salt;
    }

    /**
     * Set registered
     *
     * @param \DateTime $registered
     *
     * @return User
     */
    public function setRegistered($registered)
    {
        $this->registered = $registered;

        return $this;
    }

    /**
     * Get registered
     *
     * @return \DateTime
     */
    public function getRegistered()
    {
        return $this->registered;
    }

    /**
     * Set lastConnect
     *
     * @param \DateTime $lastConnect
     *
     * @return User
     */
    public function setLastConnect($lastConnect)
    {
        $this->lastConnect = $lastConnect;

        return $this;
    }

    /**
     * Get lastConnect
     *
     * @return \DateTime
     */
    public function getLastConnect()
    {
        return $this->lastConnect;
    }

    /**
     * Get validated
     *
     * @return boolean
     */
    public function getValidated()
    {
        return $this->validated;
    }

    /**
     * Set validated
     *
     * @param boolean $lastConnect
     *
     * @return User
     */
    public function setValidated($validated)
    {
        $this->validated = $validated;

        return $this;
    }

    /**
     * Get role
     *
     * @return int
     */
    public function getRole(){
        return $this -> role;
    }

    /**
     * Set role
     *
     * @param int $role
     *
     * @return User
     */
    public function setRole($role)
    {
        $this->role = $role;

        return $this;
    }

    /**
     * Get authMode
     *
     * @return int
     */
    public function getAuthMode(){
        return $this -> authMode;
    }

    /**
     * Set authMode
     *
     * @param $authMode
     *
     * @return $this
     */
    public function setAuthMode($authMode){
        $this->authMode = $authMode;

        return $this;
    }

    /**
     * Get isDev
     *
     * @return boolean
     */
    public function getIsDev(){
        return $this -> isDev;
    }

    /**
     * Set isDev
     *
     * @param $isDev
     *
     * @return $this
     */
    public function setIsDev($isDev){
        $this->isDev = $isDev;

        return $this;
    }

    /**
     * @return boolean
     */
    public function isIsAdvertiser()
    {
        return $this->isAdvertiser;
    }

    /**
     * @param boolean $isAdvertiser
     * @return User
     */
    public function setIsAdvertiser($isAdvertiser)
    {
        $this->isAdvertiser = $isAdvertiser;
        return $this;
    }

    /**
     * Get deviceToken
     *
     * @return String
     */
    public function getDeviceToken(){
        return $this -> deviceToken;
    }

    /**
     * Set deviceToken
     *
     * @param $deviceToken
     *
     * @return $this
     */
    public function setDeviceToken($deviceToken){
        $this -> deviceToken = $deviceToken;

        return $this;
    }

    /**
     * This method returns the User object as JSON object
     * @return mixed
     */
    public function getJsonData(){
        $var = get_object_vars($this);
        foreach($var as &$value){
            if(is_object($value) && method_exists($value,'getJsonData')){
                $value = $value->getJsonData();
            }
        }
        return $var;
    }

    /**
     * This method returns the User object as array
     * @return array
     */
    public function getArrayData(){
        return array(
            'id' => $this -> id,
            'email' => $this -> email,
            'password' => $this->password,
            'salt' => $this->salt,
            'registered' => $this->registered,
            'lastConnect' => $this -> lastConnect,
            'validated' => $this -> validated,
            'role' => $this -> role,
            'authMode' => $this->authMode,
            'isDev' => $this->isDev,
            'deviceToken' => $this->deviceToken
        );
    }

    /**
     * User constructor.
     * @param null $email
     * @param null $password
     * @param null $salt
     * @param null $registered
     * @param null $lastConnect
     * @param null $validated
     * @param null $role
     * @param null $authMode
     * @param bool|null $isDev
     * @param bool $isAdvertiser
     * @param string $deviceToken
     */
    public function __construct($email = null, $password = null , $salt = null, $registered = null, $lastConnect = null, $validated = null, $role = null, $authMode = null, $isDev = false, $isAdvertiser = false,  $deviceToken = '0')
    {
        $this -> email = $email;
        $this -> password = $password;
        $this -> salt = $salt;
        $this -> registered = $registered;
        $this -> lastConnect = $lastConnect;
        $this -> validated = $validated;
        $this -> role = $role;
        $this -> authMode = $authMode;
        $this -> isDev = $isDev;
        $this -> isAdvertiser = $isAdvertiser;
        $this -> deviceToken = $deviceToken;
    }

    /**
     * String representation of object
     * @link http://php.net/manual/en/serializable.serialize.php
     * @return string the string representation of the object or null
     * @since 5.1.0
     */
    public function serialize()
    {
        return serialize(array(
            $this->id,
            $this->email,
            $this->password,
            $this->salt
        ));
    }

    /**
     * Constructs the object
     * @link http://php.net/manual/en/serializable.unserialize.php
     * @param string $serialized <p>
     * The string representation of the object.
     * </p>
     * @return void
     * @since 5.1.0
     */
    public function unserialize($serialized)
    {
        list (
            $this->id,
            $this->email,
            $this->password,
            $this->salt
            ) = unserialize($serialized);
    }

    /**
     * Returns the roles granted to the user.
     *
     * <code>
     * public function getRoles()
     * {
     *     return array('ROLE_USER');
     * }
     * </code>
     *
     * Alternatively, the roles might be stored on a ``roles`` property,
     * and populated in any number of different ways when the user object
     * is created.
     *
     * @return (Role|string)[] The user roles
     */
    public function getRoles()
    {
        return array($this -> role);
    }

    /**
     * Returns the username used to authenticate the user.
     *
     * @return string The username
     */
    public function getUsername()
    {
        return $this -> email;
    }

    /**
     * Removes sensitive data from the user.
     *
     * This is important if, at any given point, sensitive information like
     * the plain-text password is stored on this object.
     */
    public function eraseCredentials()
    {
        // TODO: Implement eraseCredentials() method.
    }
}

And here is my repository :

<?php

namespace OneDayBundle\SolrRepository;

use FS\SolrBundle\Repository\Repository;

/**
 * Solr Repo for User entity
 * @package OneDayBundle\SolrRepository
 */
class UserRepository extends Repository
{
    public function findEmail($email)
    {
        //TODO
    }
}

Here is the SolrBundle part of my configuration file :

# FS Solr Bundle Configuration
fs_solr:
    endpoints:
        1day-users:
            host: bulk.1day-online.com
            port: 8983
            path: /solr/1day-users
            core: 1day-users
            timeout: 5
        1day-profiles:
            host: bulk.1day-online.com
            port: 8983
            path: /solr/1day-profiles
            core: 1day-profiles
            timeout: 5

Thanks for your help!

Cheers!

floriansemm commented 7 years ago

your config looks ok. This output is a result of an underlaying exception in https://github.com/floriansemm/SolrBundle/blob/master/Command/SynchronizeIndexCommand.php#L46.

I can not do so much for you.

Koalabaerchen commented 7 years ago

Is the UserRepository inside the SolrRepository folder (OneDayBundle/SolrRepository/UserRepository.php)? Make sure the namespace fits the folder it is in and the filename, especially the cases (camels and all). Symfony (or the composer autoloader) doesn't like putting something not referenced anywhere in a namespace "folder" when it's not in the exact named folder or filename.

It can't find the file when something is named wrong. Would explain the error.

Cypaubr commented 7 years ago

@Koalabaerchen Yes, all the files are in the right directory, this has already been checked. Same thing for the namespace. This is not the problem...

Koalabaerchen commented 7 years ago

Does it work if you remove the repository from the @Solr\Document annotation?

edit: Oh, and does OneDayBundle\Repository\UserRepository exist?

Cypaubr commented 7 years ago

Issue fixed just had to remove the number from core names...