swampmusic

using multi-instances with dynamic multi-sites problem

Recommended Posts

swampmusic    3

Having a problem with a basic multi-site instance.

The multi-sites are dynamically created and run as sub-domains and all is ok with them. They are created during a sign up process by end users.

During the sign up process - once the new site & db has been created, I had planned to load the new site instance and add a new user to it, using code similar to this..

$newSiteInstance = new ProcessWire($path, $newSiteUrl);
 
$u = $newSiteInstance->users->add($sitename);
$u->pass = $pass;
$u->email = $email;
$u->addRole('content-viewer');
$x = $newSiteInstance->users->save($u);

 This won't work in the registration script. It throws an error ... "SQLSTATE[42S02]: Base table or view not found".

However, if I halt the script, load the new site incognito/other browser, then continue the script, all works perfectly.

So $newSiteInstance = new ProcessWire($path, $newSiteUrl); doesn't seem to work for me unless a site has already been loaded in a browser or instantiated somehow.

I am missing something here ? Does a site need to be bootstrapped before new instance will work on it ? 

Sorry, pretty new to this php/PW arena.  Having fun though :-)

Any ideas folks ?

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By swampmusic
      Hi Folks,
      We have a multi-site #1, multiple sites, multiple databases platform in development/concept at the moment.
      A company can sign up, register, and PW then creates a db, copies over a site folder with /wire symlink. All seems to work well, after sign up they can then enter into their subdomain site. ( Because of this dirty hack below that inserts the new subdomain into PW's hostSiteConfig array. Without this, the subdomain is not correctly registered as a PW site & instance I think).
      Does anyone know how to dynamically add an entry into the index.config.php file ? Knowing the little I have learnt so far about PW, Ryan has probably left us a really smart way to do it, but I haven't figured it out or found it yet. 
      I have done a dirty hack on it, which I'm not very happy or proud off. Anybody know of a better way around the problem ?  ... below is more or else the code I am using in the pilot version.
        // some error traps taken out for brevity on the booleans below...   $hostsArray = ProcessWireHostSiteConfig(); // $sitename normally populated from the customers signup/registration // hard coded here for this example... $sitename ='somesubdomain';   $a = $sitename . '.' . 'localhost:8020';     // machine name, port & protocol normally comes from $config, hard coded for example. $b = 'site-' . $sitename . '/site'; $newSite = array($a => $b);   $hostsArray = array_merge($hostsArray, $newSite);   // very dirty hack starting.... // creating a string copy of the array used in // index.config.php $newString=''; foreach($hostsArray as $key => $value) { $newString .= "'" . $key . "' => '" . $value . "', "; } $newString = "return array(" . $newString . ');}';   // dirty hack getting worse :-( $newConfigIndex = file_get_contents($config->paths->root . 'index.config.php'); $startpos = strpos($newConfigIndex, 'return array(');   // quality coders starting to feel sick at this point i suspect... sorry! ;-( $newConfigIndex = substr_replace($newConfigIndex, $newString, $startpos);   $boolConfigIndex = file_put_contents($config->paths->root . 'index.config.php', $newConfigIndex); // crikey! did he really just do that !!!!!!    
    • By Marc
      I'm working on a process module that connects to another ProcessWire 3.0.54 installation on the same (local) server (both sites running 3.0.54). I'm trying to use multi-instance for this, so:
      namespace ProcessWire; $path = "C:/Users/Me/Documents/development/www/pw3/"; $url = "http://www.test.me"; $site = new ProcessWire($path, $url); Those simple three lines generate the following error:
      I'm probably missing something obvious here as I don't have much experience with namespaces yet. Any suggestions?
    • By Marc
      I have setup two websites, A and B. A can read pages from B using the multi-instance API. But how do I get A to save a new page to B? I have this simple test setup:
      $path = "C:/Users/Marc/Documents/development/www/siteB/"; $url = "/siteB/"; $siteB = new ProcessWire($path, $url); $np = new Page(); $np->template = "my-template"; $np->parent = $siteB->pages->get('/forms/'); $np->title = 'test multi-instance form'; $np->save(); The page is saved to site A instead of B, with no parent. Is this a case of saving it to the wrong instance? If so, how do I save it to the correct instance (site B)?
    • By Ferdi Derksen
      Hi guys,
      I was wondering if there is an option to load another site in the FieldtypePage by using the custom PHP code to find selectable pages.
      // placed as custom PHP code to find selectable pages return $content->pages->get("/")->children(); When it needs hooking into methods as "InputfieldPage::___getSelectablePages" or "InputfieldPage::___findPagesCode", I'd like to know how.
      By just placing the following code somewhere in the methods it won't work, but maybe someone else knows how?
      $content = new ProcessWire('/mypath/to/content/site/', '/content/'); // placed in subdirectory  
      Maybe it isn't even possible, but then also, I'd like to know .
    • By Can
      What am I mixing up that this won't work, or better to say will throw "..Base table or view not found..." 
      $meta = new ProcessWire($config->paths->root . 'site-meta/', "http://meta.$config->domain"); $backupPath = $config->paths->assets . 'backups/database/'; $backup = new WireDatabaseBackup($backupPath); $backup->setWire($wire); $backup->setDatabase($database); $backup->setDatabaseConfig($config); $backupFile = $backup->backup(['description' => 'saludos your Cron']); if ($backupFile) { wireZipFile("$backupFile.zip", $backupFile); exec("ln -sf $backupFile.zip {$backupPath}newest.sql"); $log->message("linked $backupFile"); unlink($backupFile); } $backupMeta = new WireDatabaseBackup($backupPath); $backupMeta->setWire($meta); $backupMeta->setDatabase($meta->database); $backupMeta->setDatabaseConfig($meta->config); $backupMetaFile = $backupMeta->backup(['description' => 'saludos your Cron']); if ($backupMetaFile) { wireZipFile("$backupMetaFile.zip", $backupMetaFile); exec("ln -sf $backupMetaFile.zip {$backupPath}newestMeta.sql"); $log->message("linked $backupMetaFile"); unlink($backupMetaFile); } if I comment one of them out they'll work properly
      if I'm trying to run both as in the snippet above the second one fails after the first tables with the above error indicating meta.field_date is missing but this field is only present in the above installation (so the "host" processwire)
      even tried to explicitly set the tables to backup for the second on with no difference
      $backupMetaFile = $backupMeta->backup(['description' => 'saludos your Cron', 'tables' => $backupMeta->getAllTables()]); var_dumping $backupMeta->getAllTables() will show the correct tables, meaning there is no reference to field_date
      tried to instantiate WireDatabaseBackup within meta by
      $backupMeta = $meta->wire(new WireDatabaseBackup($backupPath)); which works creating pages but in this case throws another error, but as both run from the same pw installation (multisite) there is only one WireDatabaseBackup anyway..
      and I also tried to specify a different path
      the code is supposed to be part of a cron, right now it sits in my site/init for testing
      So to clarify, my setup looks like this
      root - wire - site - site-meta - index.php - index.config.php everything else works as expected with this setup, so far.