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 6650471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:53:49+00:00 2026-05-26T00:53:49+00:00

I’m creating a version of an existing symfony php application which is to be

  • 0

I’m creating a version of an existing symfony php application which is to be used as sandbox, i.e. a sort of demo version of the app.
The two apps will use separate mysql schemas on the same server.
The two schemas are identical and the sandbox schema will be dropped and recreated with data from the main app at the start of each day.
During the day, users may be created/updated in the main app and I want these changes to be reflected in the sandbox app immediately – so I need to copy changes from about three related tables whenever they’re changed in the main app.

I’ve considered creating triggers on the required tables in the main schema, but i’m having little luck finding examples of AFTER INSERT and AFTER UPDATE trigger_body that do something like.

I’ve considered modifying the Doctrine objects associated with the three tables to save via a separate Doctrine_Connection (for the sandbox dsn).

I’ve considered extending the sfDoctrineGuardPlugin in the main app to provide authentication for both apps, but this would still require a transfer of data from the three tables.

Is there any method I’ve not considered here? Which method would be best?

  • 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-05-26T00:53:49+00:00Added an answer on May 26, 2026 at 12:53 am

    I solved this by doing the following in the sandbox codebase:

    • Implemented an alternative validator to sfGuardValidatorUser and pointed app.yml to this class with the auth_user_validator key.
    • Implemented a private validator method _checkMainApp which is called with the user-supplied credentials if the user is not found in the sandbox user table. It does the following:
      • set-up an ad-hoc connection to the main app db (working around some bugs symfony, doctrine)
      • query the main db for the user (and then restore the original db connection)
      • if user is found and the password is good, perform a deep copy of the object
      • finally, only the user and its profile should be copied and any other related object (available via the deep copied user) should be located in the sandbox db and should replace the existing relations – this is what _fixCopiedRelations does (in a rather cumbersome fashion).
    
    
    # lib/validator/yiValidatorUserSandbox.class.php
        protected function doClean($values)
        {
            // snip
    
            // don't allow to sign in with an empty username
            if ($username)
            {
                // snip
    
                // user exists?
                if ($user) {
                    // password is ok?
                    // snip
                } else if ($user = $this->_checkMainApp($username, $password)) {
                    return array_merge($values, array('user' => $user));
                }
            }
            // snip
        }
    
        private function _checkMainApp($username, $password)
        {
            $sandConn     = Doctrine_Core::getTable('sfGuardUser')->getConnection();
            $readOnlyConn = Doctrine_Manager::connection(
                'mysql://root@localhost/maindb', 'readonly' # readonly is only the conn name, not its state
            );
            $user = Doctrine_Core::getTable('sfGuardUser')
                ->getAllUserDetailsUsingConnection($username, $readOnlyConn);
            Doctrine_Manager::getInstance()->closeConnection($readOnlyConn);
            Doctrine_Manager::getInstance()->setCurrentConnection($sandConn->getName());
            if (   $user instanceof sfGuardUser && $user->getIsActive()
                && $user->checkPassword($password)
            ) {
                $sandboxUser = $user->copy(true);
                $this->_fixCopiedRelations($sandboxUser);
                $sandboxUser->setPasswordHash($user['password']);
                $sandboxUser->save($sandConn);
                return $sandboxUser;
            }
            return false;
        }
    
        private function _fixCopiedRelations(Doctrine_Record $rec)
        {
            $rel = $rec->getReferences();
            foreach ($rel as $name => $related) {
                if ($name == 'Responsibilities') {
                    $coll = new Doctrine_Collection('Client');
                    foreach ($related as $client) {
                        $o = Doctrine_Core::getTable('Client')->findOneByCode($client['code']);
                        if ($o instanceof Client == false) {
                            throw new UnexpectedValueException(
                                'Cannot find related object in the sandbox database, therefore not copying sfGuardUser to the sandbox.'
                            );
                        }
                        $coll->add($o);
                    }
                    $rec[$name] = $coll;
                } else if ($name == 'Groups' || $name == 'Permissions') {
                    $coll = new Doctrine_Collection(($name == 'Groups' ? 'sfGuardGroup' : 'sfGuardPermission'));
                    foreach ($related as $instance) {
                        $o = Doctrine_Core::getTable(($name == 'Groups' ? 'sfGuardGroup' : 'sfGuardPermission'))->findOneByName($instance['name']);
                        if ($o instanceof Doctrine_Record == false) {
                            throw new UnexpectedValueException(
                                'Cannot find related object in the sandbox database, therefore not copying sfGuardUser to the sandbox.'
                            );
                        }
                        $coll->add($o);
                    }
                    $rec[$name] = $coll;
                } else if ($name == 'Profile') {
                    $this->_fixCopiedRelations($related);
                } else {
                    throw new UnexpectedValueException(
                        'Method does not know how to copy this related object to the sandbox, therefore not copying sfGuardUser to the sandbox'
                    );
                }
            }
        }
    
    

    It’s worth noting that, in order to prevent _fixCopiedRelations from failing, I have to make sure that any related objects that exists in the main db also exist in the sandbox db, but the creation of new such objects is very limited so it’s not really a problem in this case.

    I’m not particularly enamoured with the solution, but it works in this limited context and it’s good enough.

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

Sidebar

Related Questions

I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

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.