We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 15066
    • 27 Posts
    Hi there ...

    I want to create (or install if it’s already created) snippet, that would copy Document Content to another database if i want that.

    I think, that the easyest way to do this would be to create a template variable, where i could choose if I want to duplicate content to another database(dropdown menu - YES / NO), or just insert it to default database.
    So, TV would have to call snippet.

    In snippet i would create connection to other database and insert all fields in another Mods site.

    For images that are uploaded in 1st page, I would use whole address so they could function on 2nd page too.

    Anyone have any ideas, if I am thinking in right way?

    Thank you for your help!

    Jure
      • 7231
      • 4,205 Posts
      If I understood correctly what you need to use is a plug-in that will record the data to a second database on save (use the OnDocFormPrerender system event). You can do whatever you want with the content fields at this point, including sending the data to a second database.
        [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]
        • 15066
        • 27 Posts
        Hello!

        Thank you for reply...

        But first i have to choose if I want to copy files - If I create plug-in they will be duplycated by default ?
        What if I use OnDocFormSave?

        How can I GET content fields? ...so i can insert them later...


        Thank you...
          • 7231
          • 4,205 Posts
          You could use a TV as a switch to activate the copy. The tv is available as part of the $_POST array by adding TV prefix to the TV name, so if your TV is named ’date’ you would use $_POST[’tvdate’];
            [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]
            • 15066
            • 27 Posts
            Hi!

            I’ve created a test, to see if plugin is started - and I don’t get any feedback.

            Plugin:
            System events: OnDocFormPrerender
            ---->
            $kopiraj = $_POST[’tvkopiraj_novico’];



            if ($kopiraj == ’yes’) {
            echo ’kopiram’;

            } else {
            echo ’ne kopiram’;
            }
            <---

            TV
            --->
            Variable name: [*kopiraj_novico*]
            Type: Dropdown list menu
            Input opt. value: Ne==no || Da==yes
            <---

            Why isn’t plugin started?

            How can i then get pagetitle, content, pub_date ... etc. ?
            So i can later insert that into another database.

            Thank you for your help.
              • 15066
              • 27 Posts
              Hello again!

              Now, i’ve tried to insert into another database:

              If i wan’t that this is working, i have to choose "OnDocFormSave"
              But, wher i start this plugin
              ------>
              $kopiraj = ’yes’;

              if ($kopiraj == ’yes’) {
              echo ’kopiram’;

              $link = mysql_connect("$server", "$dbase", "$pass") or die(mysql_error());
              mysql_select_db("$dbase", $link);

              $type = "document";
              $contentType = "text/html";
              $pagetitle = "test11111";
              $longtitle = "test";
              $description = "test";
              $alias = "test";
              $link_attributes = "";
              $published = "1";
              $pub_date = "0";
              $unpub_date = "0";
              $parent = "403";
              $isfolder = "0";
              $introtext = "test";
              $content = "test";
              $richtext = "1";
              $template = "1";
              $menuindex = "1";
              $searchable = "1";
              $cachable = "1";
              $createdby = "1";
              $createdon = "1144904400";
              $editedby = "1";
              $editedon = "1222371358";
              $deleted = "0";
              $deletedon = "0";
              $deletedby = "0";
              $publishedon = "0";
              $publishedby = "0";
              $menutitle = "test";
              $donthit = "0";
              $haskeywords = "0";
              $hasmetatags = "0";
              $privateweb = "0";
              $privatemgr = "0";
              $content_dispo = "0";
              $hidemenu = "0";


              $sql_insert = "INSERT INTO modx_site_content (type, contentType, pagetitle, longtitle, description, alias, link_attributes, published, pub_date, unpub_date, parent, isfolder, introtext, content, richtext, template, menuindex, searchable, cacheable, createdby, createdon, editedby, editedon, deleted, deletedon, deletedby, publishedon, publishedby, menutitle, donthit, haskeywords, hasmetatags, privateweb, privatemgr, content_dispo, hidemenu) VALUES (’$type’, ’$contentType’, ’$pagetitle’, ’$longtitle’, ’$description’, ’$alias’, ’$link_attributes’, ’$published’, ’$pub_date’, ’$unpub_date’, ’$parent’, ’$isfolder’, ’$introtext’, ’$content’, ’$richtext’, ’$template’, ’$menuindex’, ’$searchable’, ’$cachable’, ’$createdby’, ’$createdon’, ’$editedby’, ’$editedon’, ’$deleted’, ’$deletedon’, ’$deletedby’, ’$publishedon’, ’$publishedby’, ’$menutitle’, ’$donthit’, ’$haskeywords’, ’$hasmetatags’, ’$privateweb’, ’$privatemgr’, ’$content_dispo’, ’$hidemenu’)";
              mysql_query($sql_insert, $link);


              } else {

              echo ’ne kopiram’;
              }

              <-----

              I get serious error, the content is written to another database, but configuration page of modx is automaticly opened, and i have to choose save - or the page crashes.

              How can i get $pagetitle = $_POST[’pagetitle’]; .... ... longtitle, content .... ?
              And why isn’t this working = $kopiraj = $_POST[’tvkopiraj_novico’]; ?


              Thank you!
                • 15066
                • 27 Posts
                Any Idea ? pls sad

                I get this page, when i save document

                http://www.mvm.si/razno/error.jpg <--- Configuration page

                When I click Save(Shrani), page loads normal.

                I still have no idea, how to get in plugin all informations -> pagetitle, content, pub_date ....


                Thank you
                  • 7231
                  • 4,205 Posts
                  I use $_POST[’pagetitle’]; with OnDocFormSave, not sure if there is another way on that event. The content field has a funny name $_POST[’ta’]; not sure why it is this, never noticed it before. When in doubt just look at the name of the input fied in the source code of the edit pframe.

                  To help debug your script you can add exit points so you know how far it is going. This helps a lot to pin point the problems.

                  echo "I made it this far";
                  exit;
                    [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&#39;t know what it is.
                    Do you, Mr. Jones? - [bob dylan]
                    • 15066
                    • 27 Posts
                    Hello!

                    I’ve tried it with
                    echo & exit function...and I get to the end. I don’t get it, why default page isn’t loaded... I always get the same error... I don’t think it actualy error... when I click Shrani-Save, it’s all Ok

                    http://www.mvm.si/razno/error.jpg


                    Any other idea?

                    Thank you for your help!
                      • 7231
                      • 4,205 Posts
                      The only reason that I can think that would take you to that page rather than the standard page is if you are using a parameter that is conflicting with the MODx ones or maybe a missing closing tag ’ " } or )

                      Is the second table on the same database or is it on a remote database? If it is local then you may use the modx db:api to make the connection.
                        [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&#39;t know what it is.
                        Do you, Mr. Jones? - [bob dylan]