Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9212153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:27:34+00:00 2026-06-18T01:27:34+00:00

I’ve made a simple symfony2 console script which is supposed to convert data from

  • 0

I’ve made a simple symfony2 console script which is supposed to convert data from old model to the new one.
Here’s what it looks like:

class ConvertScreenshotsCommand extends Command 
{
[...]
protected function execute(InputInterface $input, OutputInterface $output)
{
    $em = $this->getContainer()->get('doctrine')->getManager();

    $output->writeln('<info>Conversion started on ' . date(DATE_RSS) . "</info>");

    $output->writeln('Getting all reviews...');
    $reviews = $em->getRepository('ACCommonBundle:Review')->findAll(); // Putting all Review entities into an array
    $output->writeln('<info>Got ' . count($reviews) . ' reviews.</info>');

    foreach ($reviews as $review) {
        $output->writeln("<info>Screenshots for " . $review->getTitle() . "</info>");
        if ($review->getLegacyScreenshots()) {
            foreach ($review->getLegacyScreenshots() as $filename) { // fn returns array of strings
                $output->writeln("Found " . $filename);
                $screenshot = new ReviewScreenshot();        // new object

                $screenshot->setReview($review);     // review is object
                $screenshot->setFilename($filename); // filename is string

                $em->persist($screenshot);
                $em->flush();                        // this is where it dies
                $output->writeln("Successfully added to the database.");
            }
        } else $output->writeln("No legacy screenshots found.");
    }
    $output->writeln('<info>Conversion ended on ' . date(DATE_RSS) . "</info>");
 }
 }

The script breaks on $em->flush(), with the following error:

 [ErrorException]                                                                                                                                                       
 Warning: spl_object_hash() expects parameter 1 to be object, string given in      
 /[...]/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php line 1324     

Obviously I’m doing something wrong, but can’t figure out what it is. Thanks in advance!

** Update **

Review Entity mapping:

class Review
{
[...]

/**
 * @ORM\OneToMany(targetEntity="ReviewScreenshot", mappedBy="review")
 */
protected $screenshots;

/**
 * Won't be stored in the DB
 * @deprecated
 */
private $legacyScreenshots;

/**
 * New method to get screenshots, currently calls old method for the sake of compatibility
 * @return array Screenshot paths
 */

public function getScreenshots()
{
//        return $this->getLegacyScreenshots();  // Old method
    return $this->screenshots;                   // New method
}


/**
 * Get Screenshot paths
 * @return array Screenshot paths
 * @deprecated
 */
public function getLegacyScreenshots()
{
    $dir=$this->getUploadRootDir();
    if (file_exists($dir)) {
        $fileList = scandir($dir);

    $this->screenshots = array();
    foreach ($fileList as $fileName)
    {
        preg_match("/(screenshot-\d+.*)/", $fileName, $matches);
        if ($matches)
            $this->screenshots[]=$matches[1];
    }
    return $this->screenshots;
    }
    else return null;
}

ReviewScreenshot mapping:

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

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

/**
 * @ORM\ManyToOne(targetEntity="Review", inversedBy="screenshots")
 * @ORM\JoinColumn(name="review_id", referencedColumnName="id")
 */
protected $review;

/**
 * @var integer $priority
 *
 * @ORM\Column(name="priority", type="integer", nullable=true)
 */
protected $priority;

/**
 * @var string $description
 *
 * @ORM\Column(name="description", type="string", nullable=true)
 */
protected $description;

/**
 * @Assert\File(maxSize="2097152")
 */
public $screenshot_file;

protected $webPath;

UnitOfWork.php

/**
 * Gets the state of an entity with regard to the current unit of work.
 *
 * @param object $entity
 * @param integer $assume The state to assume if the state is not yet known (not MANAGED or REMOVED).
 *                        This parameter can be set to improve performance of entity state detection
 *                        by potentially avoiding a database lookup if the distinction between NEW and DETACHED
 *                        is either known or does not matter for the caller of the method.
 * @return int The entity state.
 */
public function getEntityState($entity, $assume = null)
{
    $oid = spl_object_hash($entity); // <-- Line 1324

    if (isset($this->entityStates[$oid])) {
        return $this->entityStates[$oid];
    }

    if ($assume !== null) {
        return $assume;
    }

    // State can only be NEW or DETACHED, because MANAGED/REMOVED states are known.
    // Note that you can not remember the NEW or DETACHED state in _entityStates since
    // the UoW does not hold references to such objects and the object hash can be reused.
    // More generally because the state may "change" between NEW/DETACHED without the UoW being aware of it.
    $class = $this->em->getClassMetadata(get_class($entity));
    $id    = $class->getIdentifierValues($entity);

    if ( ! $id) {
        return self::STATE_NEW;
    }

    switch (true) {
        case ($class->isIdentifierNatural());
            // Check for a version field, if available, to avoid a db lookup.
            if ($class->isVersioned) {
                return ($class->getFieldValue($entity, $class->versionField))
                    ? self::STATE_DETACHED
                    : self::STATE_NEW;
            }

            // Last try before db lookup: check the identity map.
            if ($this->tryGetById($id, $class->rootEntityName)) {
                return self::STATE_DETACHED;
            }

            // db lookup
            if ($this->getEntityPersister($class->name)->exists($entity)) {
                return self::STATE_DETACHED;
            }

            return self::STATE_NEW;

        case ( ! $class->idGenerator->isPostInsertGenerator()):
            // if we have a pre insert generator we can't be sure that having an id
            // really means that the entity exists. We have to verify this through
            // the last resort: a db lookup

            // Last try before db lookup: check the identity map.
            if ($this->tryGetById($id, $class->rootEntityName)) {
                return self::STATE_DETACHED;
            }

            // db lookup
            if ($this->getEntityPersister($class->name)->exists($entity)) {
                return self::STATE_DETACHED;
            }

            return self::STATE_NEW;

        default:
            return self::STATE_DETACHED;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T01:27:35+00:00Added an answer on June 18, 2026 at 1:27 am

    I think the problem lies within Review::$screenshots:

    You map it as a OneToMany association, so the value should be a Collection of ReviewScreenshot entities. But the method Review::getLegacyScreenshots() will change it into an array of strings.

    You’re probably using the change-tracking policy DEFERRED_IMPLICIT (which is the default). So when the property Review::$screenshots changes, Doctrine will try to persist that change, encounters strings where it expects entities, so throws the exception.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an autohotkey script which looks up a word in a bilingual dictionary
I have a text area in my form which accepts all possible characters from
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm making a simple page using Google Maps API 3. My first. One marker
I am using jsonparser to parse data and images obtained from json response. When
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.