Modulshop - Eine große Auswahl an neuen und hilfreichen Modulen für die modified eCommerce Shopsoftware
Neuigkeiten
  • Die modified eCommerce Shopsoftware ist kostenlos, aber nicht umsonst.
    Spenden
  • Damit wir die modified eCommerce Shopsoftware auch zukünftig kostenlos anbieten können:
    Spenden
  • Thema: Imageprocessing automatisch starten

    NiceGuy_Eddie

    • Neu im Forum
    • Beiträge: 11
    Imageprocessing automatisch starten
    am: 28. Februar 2011, 09:14:07
    moin,

    ich habe vor kurzem eine etwas angepasste easypopulate-Contrib im modified eCommerce Shopsoftware-System integriert.
    Die Übertragung der Artikel funktioniert bisher auch wie gewünscht.

    Allerdings ist es ja anschließend noch notwendig, das Imageprocessing zu starten.
    Daher habe ich mich gefragt, ob es möglich ist, das nach dem Artikelimport automatisch starten zu lassen.

    Bisher hatte ich keinen Erfolg dabei, die Funktion in der image_processing_step.php aufzurufen bzw. anzustoßen.
    Ist das überhaupt der richtige Ansatz?

    Hoffe Ihr könnt mir weiterhelfen.
    thx



    Linkback: https://www.modified-shop.org/forum/index.php?topic=11290.0
    Templateshop - Eine große Auswahl an neuen und modernen Templates für die modified eCommerce Shopsoftware

    NiceGuy_Eddie

    • Neu im Forum
    • Beiträge: 11
    Imageprocessing automatisch starten
    Antwort #1 am: 02. März 2011, 12:50:22
    also ich versuche das momentan mit cURL umzusetzen.
    Wenn ich mich nicht irre, muss ich ja dabei mehrere Parameter mittels CURLOPT_POSTFIELDS mitgeben.

    hier mal ein Auszug:

    Code: PHP  [Auswählen]
    $cUrl = curl_init('http://www.shopurl.de/admin/module_export.php');
    curl_setopt($cUrl, CURLOPT_POST, 1);
    curl_setopt($cUrl, CURLOPT_POSTFIELDS, 'action=save&module=image_processing_new_step&start=50');
    curl_setopt($cUrl, RETURNTRANSFER, 1);
    curl_setopt($cUrl, COOKIEFILE, $cookie);
    curl_exec($cUrl);
    curl_close($cUrl);

    Bewege ich mich auf dem richtigen Weg?

    NiceGuy_Eddie

    • Neu im Forum
    • Beiträge: 11
    Re: Imageprocessing automatisch starten
    Antwort #2 am: 28. September 2011, 13:59:21
    Hey,
    nachdem ich diese Funktion vorübergehend anders gelöst hatte, möchte ich es nun doch auf die ursprüngliche Weise realisieren.

    Ich habe mithilfe einiger Tutorial das passende cURL Script erstellt:

    Code: PHP  [Auswählen]
    <?php

    curl_login('http://shop.de/login.php?action=process' , 'email_address=email%40domain.de&password=123456&x=72&y=25','','off');
    echo curl_grab_page('http://shop.de/admin/module_export.php?set=&module=image_processing_step&start=0&count=&action=image_processing_do&max=5&miss=1','', 'off');


    function curl_login($url,$data,$proxy,$proxystatus) {
           
            $fp = fopen("cookies.txt","w");
            fclose($fp);
            $login = curl_init();
           
            curl_setopt($login, CURLOPT_COOKIEJAR, "cookies.txt");
            curl_setopt($login, CURLOPT_COOKIEFILE, "cookies.txt");
             curl_setopt($login, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE
    5.01; Windows NT 5.0)"
    );
           
            curl_setopt($login, CURLOPT_TIMEOUT, 4000);
            curl_setopt($login, CURLOPT_RETURNTRANSFER, 1);
           
            if($proxystatus == 'on') {
                    curl_setopt($login, CURLOPT_SSL_VERIFYHOST, false);
                    curl_setopt($login, CURLOPT_HTTPPROXYTUNNEL, true);
                    curl_setopt($login, CURLOPT_PROXY, $proxy);
            }
           
            curl_setopt($login, CURLOPT_URL, $url);
            curl_setopt($login, CURLOPT_HEADER, 1);
            curl_setopt($login, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);  
            curl_setopt($login, CURLOPT_FOLLOWLOCATION, false);                                                                                                
            curl_setopt($login, CURLOPT_POST, 1);                                                                                      
            curl_setopt($login, CURLOPT_POSTFIELDS, $data);                                                                                    
           
            ob_start();
            return curl_exec($login);
            ob_end_clean();
            curl_close($login);
            unset($login);
           
    }



            function curl_grab_page($site,$proxy,$proxystatus){
       $ch = curl_init();
       curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
       if ($proxystatus == 'on') {
           curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
           curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE);
           curl_setopt($ch, CURLOPT_PROXY, $proxy);
       }
       curl_setopt($ch, CURLOPT_TIMEOUT, 6000);
       curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt");
       curl_setopt($ch, CURLOPT_URL, $site);
       ob_start();      // prevent any output
       return curl_exec ($ch); // execute the curl command
       ob_end_clean();  // stop preventing output
      curl_close ($ch);
    }

    Damit wird man eingeloggt und das "XT-Imageprocessing" gestartet.
    Allerdings wird während der Bildverarbeitung ja die Seite regelmäßig aktualisiert.
    Dadurch geht anscheinend die Session verloren und man wird wieder ausgeloggt, bevor die Verarbeitung abgeschlossen ist.
    Hat mir jemand einen Tipp, wie ich das umgehen kann?

    h-h-h

    • modified Team
    • Beiträge: 4.562
    Re: Imageprocessing automatisch starten
    Antwort #3 am: 28. September 2011, 14:06:54
    Welches Imageprocessing-Modul?

    Gruß h-h-h

    NiceGuy_Eddie

    • Neu im Forum
    • Beiträge: 11
    Re: Imageprocessing automatisch starten
    Antwort #4 am: 28. September 2011, 14:08:41
    "XT-Imageprocessing-New -V2-"

    h-h-h

    • modified Team
    • Beiträge: 4.562
    Re: Imageprocessing automatisch starten
    Antwort #5 am: 28. September 2011, 14:30:10
    Da muss vermutlich die Session in der "Wiederaufruf-URL" hinzugefügt werden.

    Gruß h-h-h

    NiceGuy_Eddie

    • Neu im Forum
    • Beiträge: 11
    Re: Imageprocessing automatisch starten
    Antwort #6 am: 28. September 2011, 14:57:25
    alles klar, danke!
    Woran ich erst nicht gedacht habe, dass sich die URL ja ständig ändert (durch den Bild-Counter usw.). Das heißt, das Script muss dann die aktuelle URL abfragen und die Session einfügen. Falls ich mich irre, freue ich mich über Kommentare.

    NiceGuy_Eddie

    • Neu im Forum
    • Beiträge: 11
    Re: Imageprocessing automatisch starten
    Antwort #7 am: 28. September 2011, 23:13:04
    Ok, hab's hinbekommen.
    In Kürze folgt hier noch der Code.
    Wird jetzt noch getestet, aber sieht ganz gut aus bis jetzt.

    Ist zwar quick... naja eher "slow & dirty", aber es erfüllt seinen Zweck.
    Funktionsweise: Ich lasse die URL für's "XT-Imageprocessing" Modul mit 'ner Schleife so oft aufrufen, bis irgendwann mal "Fertig" bei der Bildverarbeitung steht.
    Bei jedem Durchlauf wird der Start-Wert in der URL um 5 erhöht, da pro Durchlauf 5 Bilder verarbeitet werden.

    Sieht da jemand irgendein Problem, an das ich nicht gedacht habe?

    NiceGuy_Eddie

    • Neu im Forum
    • Beiträge: 11
    Re: Imageprocessing automatisch starten
    Antwort #8 am: 29. September 2011, 19:28:30
    Also hier noch der vollständige Code:

    Code: PHP  [Auswählen]
    <?php

    // Cookie File
    $cookiefile = "cookies.txt";
    $agent     = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";

    //URL der Login-Seite
    $url = 'http://www.domain.de/login.php?action=process';

     //  Login-Daten - Am besten einmal normal einloggen und mit Live HTTP Headers die Zeile unter content-length auslesen und hier eintragen
    $data = 'email_address=email%40domain.de&password=passwort&x=zahl&y=zahl';

    // =============== Login

            // CURL initialisieren
            $ch = curl_init();
           
            // Cookiedatei festlegen
            curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
            curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);
            curl_setopt($ch, CURLOPT_USERAGENT, $agent);


                    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                    if ($proxystatus == 'on') {
                       curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
                       curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE);
                       curl_setopt($ch, CURLOPT_PROXY, $proxy);
                    }

                    curl_setopt($ch, CURLOPT_URL, $url);
                    //      curl_setopt($ch, CURLOPT_HEADER, 1);
                    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);  
                    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
                    curl_setopt($ch, CURLOPT_POST, 1); // set POST method
                    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);           

                    //CURL ausführen
                    $result = curl_exec($ch);
                   
                    // Ergebnisseite anzeigen
                    echo $result;

    // ================ BILDVERARBEITUNG


    // Einfache Stringsuche, um zu prüfen ob die Bildverarbeitung abgeschlossen ist.
    $needle = 'Fertig';
    $pos = strpos($result, $needle);
     
     
    $counter = 0;

    // Schleife bis der String gefunden wird
    while ($pos < 1)
    {
            // URL des Imageprocessing-Moduls mit den zusätzlichen Werten
             $url  = "http://www.domain.de/admin/module_export.php?set=&module=image_processing_step&start=".$counter."&count=&action=image_processing_do&max=5&miss=1";
        // CURL ist bereits initialisiert
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_USERAGENT, $agent);
        curl_setopt($ch, CURLOPT_POST, 0); // set POST method
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        //Remember to use the same cookiefile as above
        curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
        curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
        // CURL ausführen
        $result = curl_exec($ch);
           
        // Jede neue Seite wird erneut durchsucht
            $needle = 'Fertig';
            $pos = strpos($result, $needle);
            $counter = $counter + 5;
    }
    // Seite anzeigen
    echo $result;
    // ========= fertig

    //  CURL  schließen
    curl_close($ch);

    ?>

    Ich mache mir noch Gedanken was das Thema Sicherheit betrifft.
    Freue mich diesbezüglich über Feedback.
    2 Antworten
    2564 Aufrufe
    11. Dezember 2011, 20:06:44 von HeimUndCo
    2 Antworten
    3182 Aufrufe
    11. Mai 2012, 21:43:05 von mahagma
    2 Antworten
    572 Aufrufe
    07. Februar 2023, 17:40:53 von svenyo
    3 Antworten
    3066 Aufrufe
    26. April 2013, 13:59:10 von sacrion