We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 5070
    • 36 Posts
    Thank you for your long reply,
    1. I have configured production box as the remote DB and Ftp server, i tested and made sure that the Production server was configured correctly.
    2. At staging box i run startModxDBServer.sh successfully.
    3. I tried to run : modxDBClient createDocument mylocalDB 50 but nothing happened, no message returned after pressing enter key. You can see my config file attached and please let’s me know if there are any wrong configurations.
    thanks.

      • 24719
      • 194 Posts
      in the server.properties.inc.php file, the array keys correspond to the values of the foreignDB key in each entry in the client.properties.inc.php file.

      so, given your client.properties.inc.php file, your server.properties.inc.php file should look like:

      $dbData['orchidslingshot'] = array(
          'db' => 'orchidslingshot',
          'dbUser' => 'orchidslingshot',
          'dbPassword' => '$orchidslingshot',
          'dbHost' => 'arctosgroup.com',
          );
      


      you then invoke it in your case with:

      modxDBClient createDocument project1-dev 50


      You need to use project1-dev because that is the value of a key in your client.properties.inc.php file.

      Hopefully things should work after these changes.

        • 5070
        • 36 Posts
        hi, I tried to configure files as you told. when i run the createDocument command, it return error :
        "Caught exception: Could not connect to testbox:2001 - Operation now in progress"
        I changed the testbox to the local machine name but got same error and saw nothing has been changed to databsae. I think there are something wrong because my StagingBox and Devbox is on the same machine running Samba.
        can you give suggestion for my situation? huh
          • 24719
          • 194 Posts
          don’t worry about that exception. i tried for ages to get rid of it, with no success. you’re right to change testbox to the name of your staging server (make sure you can ’ping’ it by name. otherwise update your /etc/hosts file).

          to get more feedback that the system is working, instead of using the shell script to start the modxDBServer when your staging machine loads, start it manually in a terminal. if modxDBServer is set to start when your server starts, do the following:

          ps -A | grep modxDBServer
          


          if you get output like:
           2826 ?        00:00:03 modxDBServer


          type:

          kill 2826


          then, start the server manually in a terminal

          /usr/local/bin/modxDBServer/modxDBServer


          Now, try using modxDBClient on the other machine. For instance, if you have configured the db dump script and run ’downloadDB’, you should see information in the server terminal such as:

          [modxDBServer] accepted connection from 192.168.1.3
          received: getDB?name=mydb&db=mydb&localdb=mydb-dev--END--
          connecting to yourserver.com
          log in successful
          retrieving /files/mydb-content.sql.gz
          ftp done
          [modxDBServer] 192.168.1.3 disconnected
          


          you’ll get similar information when creating documents, etc that can be used for debugging.
            • 7231
            • 4,205 Posts
            @redman: thank you so much for the patience to go through this step-by-step. I am learning quite a bit and may even build up the courage to try this out myself. grin
              [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

              Something is happening here, but you don't know what it is.
              Do you, Mr. Jones? - [bob dylan]
              • 5070
              • 36 Posts
              hi redman,
              after several hours see the configurations code and apply all your suggestions, this tool may be better, now i can :
              - dump database form Production server into file and download it to Development server
              - Insert new Documents, Chunks and Snippets into database of Production server
              But it can not interact with the database of Development server such as: overwriting the DevDB or insert new ID for new documents, snippet, chunks. I saw my client.properties.inc.php file and it seem to be well configured, I also add the "development Server name" to my host file and can ping it successfully, but don’t know why it can’t connect with production server to make changes.
              do you thing there is something concern with the message : Caught exception: Could not connect to productionsever.net:2001 - Operation now in progress?
              ps: I’m don’t have staging database, i only have development database located in sambar server and i use Putty to connect and run command.
                • 24719
                • 194 Posts
                hmm, i’m not sure why you’d be able to create new documents on the production machine, but not on development. this sounds like it’s either a permissions issue with your db user, or some kind of error with the data being returned by modxDBServer.

                If you insert the following into modxDBClient inside the createDocument($header, $params) method, you might have more info:

                die("header: " . $header['ID'] . ", parent: " . $params['parent']);
                


                make sure both of these are set with integer values > 0, and compare them with the new document on production. Then change the prepared statement to ordinary SQL and see if you can connect to your dev db using the details in your config file. It’s probably best to do this on the command line or using phpMyAdmin or something instead of PHP. Then execute the INSERT statement and see if it works. is it possible that the user doesn’t have INSERT or UPDATE privileges for some reason?

                the exception that is reported "Caught exception: Could not connect to productionsever.net:2001 - Operation now in progress" is not a real problem. This is caused because for some reason a different part of the class (the scheduler i think) tries to send some data over the socket before it has been full prepared, or tries to open it a second time after it is open. Because the exception is caught, there isn’t a problem. Like i said before, i tried for ages to get rid of this, but it doesn’t affect the client or server at all.

                there’s also no requirement to use a staging db, so this won’t be a problem, and you should be fine running via putty.

                @dev_cw: no worries!
                  • 24719
                  • 194 Posts
                  ps - i’ve also just spotted a bug that you might be experiencing a bit as well.

                  when you run ’createDocument’, it may print out

                  Undefined index:  ID in /path/to/modxDBServer/modxDBClient on line 423
                  


                  just edit that line, changing $params[’ID’] to $header[’ID’] to get rid of this.
                    • 5070
                    • 36 Posts
                    thanks redman,
                    i pasted the code into right place but the program seems not to use this createDocument function which is used to create a document with the given ID on Development server , No line was printed out.

                    I notice that, in the modxDBClient source code contains these lines of code:
                           // call the correct handler, and pass parameters
                           switch ($resource)
                           {
                           case 'createDocument':
                           case 'unpublishDocument':
                           case 'createSnippet':
                           //case 'deleteSnippet':
                           case 'createChunk':
                           //case 'deleteChunk':
                               $this->connectToDB($params['localdb']);
                           case 'getDB':
                               return $this->$resource($headerArray, $params);
                               break;
                           default:
                               throw new Exception("Invalid method '$resource' requested.");
                               break;
                           }

                    i tried put the function createDocument in Case ’createDocument’: but it didn’t work. I can’t find any references to this function. this is the code of it:
                        private function createDocument($header, $params)
                        {
                        	die("header: " . $header['ID'] . ", parent: " . $params['parent']);
                            // insert the new doc
                            $stmt = $this->dbh->prepare('INSERT INTO `modx_site_content` (`id`, `parent`) VALUES (?, ?)');
                            $stmt->bind_param('ii', $header['ID'], $params['parent']);
                            $stmt->execute();
                            
                            echo "{$params['resource']}: Inserted {$stmt->affected_rows} row(s).\n";
                            
                            $stmt->close();
                            
                            // make the parent a folder
                            $stmt = $this->dbh->query('UPDATE `modx_site_content` SET `isfolder`=1 WHERE `id`=?');
                            $stmt->bind_param('i', $params['parent']);
                            $stmt->execute();
                            $stmt->close();
                    die("header: " . $header['ID'] . ", parent: " . $params['parent']);        
                        }

                    do you think there is any way we are working on the old version of files?
                      • 24719
                      • 194 Posts
                      chienquang, the line below means that it’s calling the method called $resource, and since there’s a switch case for ’createDocument’, it can call the createDocument ok, so that’s not the problem:

                      return $this->$resource($headerArray, $params);


                      but, i think you might have found the problem. try replacing your createDocument method with the code below. please let me know if it works and i’ll release an update. thanks.

                      private function createDocument($header, $params)
                          {
                              // insert the new doc
                              $stmt = $this->dbh->prepare("INSERT INTO `modx_site_content` (`id`, `parent`) VALUES (?, ?) ON DUPLICATE KEY UPDATE `parent`=?,`pagetitle`='',`longtitle`='',`description`='',`alias`='',`content`=''");
                              $stmt->bind_param('iii', $header['ID'], $params['parent'], $params['parent']);
                              $stmt->execute();
                      
                              echo "{$params['resource']}: Inserted {$stmt->affected_rows} row with ID {$header['ID']}.\n";
                      
                              $stmt->close();
                      
                              // add the ID to the index file in /sql/documents/indexes
                              $indexFile = realpath(dirname(__FILE__) . '/../../sql/documents') . '/indexes';
                              system("echo '{$header['ID']}' >> $indexFile");
                      
                              // make the parent a folder
                              $stmt = $this->dbh->prepare('UPDATE `modx_site_content` SET `isfolder`=1 WHERE `id`=?');
                      $stmt->bind_param('i', $params['parent']);
                              $stmt->execute();
                              $stmt->close();
                          }