skript aus der kommandozeile starten

belubaba

belubaba

Tripel-As
Hallo,

ich habe ein Skript das kann ich aus meiner Webanwendung per Button starten. Ich würde das gerne zyklisch einplanen. Aber mein PHP ist leider zu schlecht um die Übergabeparameter zu identifizieren und in meinem Apachelog tauchen die Paramter nicht auf.

Kann mir jemand der fit in PHP ist den Aufruf zusammentippen :) (skript heisst googlebase.php)

PHP:
 class googlebase {
   var $code, $title, $enabled, $description;

   function googlebase() {
     global $messageStack;

                       $this->code = 'googlebase';
     $this->title = 'Google Base - Export Modul';
     $this->description = 'Exportiert Artikeldaten für die Preissuchmaschine <b>googleBase</b> in eine Textdatei.';
     $this->enabled = ((MODULE_EXPORT_FROOGLE_STATUS == 'true') ? true : false);

                       if(isset($_GET['exec']) && ($_GET['exec']=='export') && $this->enabled && $this->check()) {
                               $result = $this->export_psm_data();
                               if($result) {
                                       $messageStack->add_session('Exportdatei [ ' . MODULE_EXPORT_FROOGLE_FILENAME . ' ] erfolgreich in [ ' . DIR_FS_DOCUMENT_ROOT.'export/' . ' ] erstellt.', 'success');
                               }
                               else {
                                       $messageStack->add_session('Fehler beim Erstellen der Exportdatei [ ' . DIR_FS_DOCUMENT_ROOT.'export/'.MODULE_EXPORT_FROOGLE_FILENAME . ' ]', 'error');
                               }

                               if(MODULE_EXPORT_FROOGLE_DOWNLOAD == 'true') {
                                       tep_redirect(tep_href_link(FILENAME_DOWNLOAD, 'set=export' . '&module=' . $this->code . '&file=' . MODULE_EXPORT_FROOGLE_FILENAME));
                               }
                               else {
                                       tep_redirect(tep_href_link(FILENAME_MODULES, 'set=export' . '&module=' . $this->code));
                               }
                       }
   }

               function process() {
                       return false;
   }

   function check() {
     if (!isset($this->_check)) {
       $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_EXPORT_FROOGLE_STATUS'");
       $this->_check = tep_db_num_rows($check_query);
     }

     return $this->_check;
   }

   function keys() {
     return array(
                               'MODULE_EXPORT_FROOGLE_STATUS',
                               'MODULE_EXPORT_FROOGLE_DOWNLOAD',
                               'MODULE_EXPORT_FROOGLE_FILENAME',
                               'MODULE_EXPORT_FROOGLE_DATE'
                       );
   }

   function install() {
     tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Modul Status:', 'MODULE_EXPORT_FROOGLE_STATUS', 'true', 'Wert auf \'true\' setzen, um Modul zu aktivieren.', '6', '1','tep_cfg_select_option(array(\'true\', \'false\'), ', now())");
     tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Datei herunterladen:', 'MODULE_EXPORT_FROOGLE_DOWNLOAD', 'true', 'Wert auf \'true\' setzen, um die Datei auf dem Server zu speichern und herunterzuladen. Wert auf auf \'false\' setzen, um die Datei nur auf dem Server zu speichern.', '6', '2','tep_cfg_select_option(array(\'true\', \'false\'), ', now())");
                       tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Dateiname:', 'MODULE_EXPORT_FROOGLE_FILENAME', 'google_base.txt', 'Hier den Namen der Export-Datei eingeben.', '6', '3', now())");
                       tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Gültigkeit in Tagen:', 'MODULE_EXPORT_FROOGLE_DATE', '30', 'Gültigkeit in Tagen der Artikel.', '6', '4', now())");
               }

   function remove() {
     tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
   }

               function export_psm_data() {
                       global $currencies;
                       global $languages_id;
                       $languages_id = 1;

                       //
                       // Konfiguration - start
                       //
                       $result = 0;
                       $hFile = @fopen(DIR_FS_DOCUMENT_ROOT.'export/'.MODULE_EXPORT_FROOGLE_FILENAME, 'w');
                       //
                       $sEOL = "\n";
                       $fDelimiter = "\t";
                       $cDelimiter = ", ";
                       $nLenDesc = 10000;
                       //
                       $aPsmHeader = array(
                               'products_id' => 'id',
                               'products_url' => 'link',
                               'products_name' => 'titel',
                               'products_description' => 'beschreibung',
                               'products_image' => 'bild_url',
                               'products_price' => 'preis',
                               //'category' => 'bewertungsart',
                               'gdate' => 'verfallsdatum',
                               //'keywords' => 'label'
                       );
                       //
                       $oQuery = tep_db_query(
                               "SELECT DISTINCT " .
                                               "pd.products_name, " .
                                               "pd.products_description, " .
                                               "p.products_price, " .
                                               "p.products_image, " .
                                               "p.products_image_med, " .
                                               "p.products_image_lrg, " .
                                               "p.products_model, " .
                                               "p.products_quantity, " .
                                               "p.products_date_added, " .
                                               "p.products_weight, " .
                                               "p.products_status, " .
                                               "p.product_sort_order, " .
                                               "p.products_id, " .
                                               "p.manufacturers_id, " .
                                               "m.manufacturers_name, " .
                                               "p.products_tax_class_id " .
                                       "FROM " .
                                               TABLE_PRODUCTS_DESCRIPTION . " pd, " .
                                               TABLE_PRODUCTS . " p left join " .
                                               TABLE_MANUFACTURERS . " m on p.manufacturers_id = m.manufacturers_id, " .
                                               TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " .
                                               TABLE_CATEGORIES . " c " .
                                       "WHERE " .
                                               "c.categories_id = p2c.categories_id and " .
                                               "c.categories_status = '1' and " .
                                               "p.products_status = '1' and " .
                                               "p.products_id = p2c.products_id and " .
                                               "pd.products_id = p2c.products_id and " .
                                               "pd.language_id = '" . $languages_id . "' " .
                                       "ORDER BY " .
                                               "c.parent_id, " .
                                               "pd.products_name"
                       );
                       $nNumRows = tep_db_num_rows($oQuery);
                       //
                       // Konfiguration - stop
                       //

                       if($nNumRows > 0) {
                               //
                               // Header schreiben
                               //
                               @fwrite($hFile, implode($fDelimiter, $aPsmHeader) . $sEOL);

                               while($p = tep_db_fetch_array($oQuery)) {
                                       //
                                       // Datensatz vorbereiten
                                       //
                                       $sFinalRow = '';
                                       foreach($aPsmHeader as $key => $val) {
                                               switch($key) {
                                                       case 'products_url':
                                                               $sFinalRow .= tep_catalog_href_link('index.php', 'page_module=product_info&products_id=' . $p['products_id']);
                                                               $sFinalRow .= $fDelimiter;
                                                               break;

                                                       case 'gdate':
                                                               // Beispiel: 2005-12-20
                                                               $timestamp = time() + (MODULE_EXPORT_FROOGLE_DATE * 24 * 60 * 60);
                                                               $to_date = date('Y-m-d', $timestamp);
                                                               $sFinalRow .= $to_date;
                                                               $sFinalRow .= $fDelimiter;
                                                               break;

                                                       case 'products_name':
                                                               $sFinalRow .= trim($p['products_name']);
                                                               $sFinalRow .= $fDelimiter;
                                                               break;

                                                       case 'products_id':
                                                               $sFinalRow .= $p['products_id'];
                                                               $sFinalRow .= $fDelimiter;
                                                               break;

                                                       case 'products_description':
                                                               $tmp = tep_replace_user_links(stripslashes($p['products_description']));
                                                               $tmp = strip_tags(trim($tmp));
                                                               $tmp = preg_replace('/\s\s+/', ' ', $tmp);
                                                               $tmp = str_replace (chr(10), "", $tmp);
                                                               $tmp = str_replace (chr(13), "", $tmp);
                                                               $tmp = trim($this->break_string(trim($tmp), $nLenDesc));
                                                               $tmp = rtrim($tmp, '.') . '.';
                                                               $sFinalRow .= $tmp.$fDelimiter;
                                                               break;

                                                       case 'products_image':
                                                               if(tep_not_null($p['products_image_lrg'])) {
                                                                       $sFinalRow .= HTTP_SERVER . DIR_WS_CATALOG . 'images/' . $p['products_image_lrg'];
                                                               }
                                                               elseif(tep_not_null($p['products_image_med'])) {
                                                                       $sFinalRow .= HTTP_SERVER . DIR_WS_CATALOG . 'images/' . $p['products_image_med'];
                                                               }
                                                               elseif(tep_not_null($p['products_image'])) {
                                                                       $sFinalRow .= HTTP_SERVER . DIR_WS_CATALOG . 'images/' . $p['products_image'];
                                                               }
                                                               else {
                                                                       $sFinalRow .= '';
                                                               }
                                                               $sFinalRow .= $fDelimiter;
                                                               break;

                                                       case 'products_price':
                                                               $price = $this->get_products_special_price($p['products_id']);
                                                               if(!$price) {
                                                                       $price = $p['products_price'];
                                                               }
                                                               $price = tep_add_tax($price, tep_get_tax_rate($p['products_tax_class_id']));
                                                               $price = number_format($price, 2, ',', '.');
                                                               $sFinalRow .= $price.$fDelimiter;
                                                               break;

                                                       case 'keywords':
                                                               $sFinalRow .= $this->get_category_path($p['products_id'], $cDelimiter);
                                                               $sFinalRow .= $fDelimiter;
                                                               break;

                                                       case 'category':
                                                               $cat_word = explode('|', $this->get_category_path($p['products_id'], '|'));
                                                               $sFinalRow .= $cat_word[0];
                                                               $sFinalRow .= $fDelimiter;
                                                               break;

                                                       default:
                                                               break;
                                               }
                                       }

                                       //
                                       // Datensatz schreiben
                                       //
                                       $sFinalRow = substr($sFinalRow, 0, -1);
                                       if(fwrite($hFile, $sFinalRow . $sEOL)) {
                                               $result++;
                                       }
                                       else {
                                               $result = 0;
                                               break;
                                       }
                               }
                       }

                       @fclose($hFile);

                       return $result > 0 ? true : false;
               }

               function get_category_path($products_id, $delimiter) {
                       global $languages_id;
                       $languages_id = 1;

                       // Ermittle den Category-Pfad zu einem Produkt
                       $s_path = $this->get_product_path($products_id);
                       $path_list = explode('_', $s_path);

                       for($i=0; $i < count($path_list); $i++) {
                                       $query = tep_db_query("select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id = '" . (int)$path_list[$i] . "' and language_id = '" . $languages_id . "'");
                                       $category = tep_db_fetch_array($query);

                                       if(!empty($category['categories_name'])) {
                                               if($i < count($path_list) - 1)
                                                       $category_path .= $category['categories_name'] . $delimiter;
                                               else
                                                       $category_path .= $category['categories_name'];
                                       }
                               }

                       return trim($category_path);
               }

               function get_product_path($products_id) {
                       $cPath = '';

                       $category_query = tep_db_query("select p2c.categories_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = '" . (int)$products_id . "' and p.products_id = p2c.products_id limit 1");
                       if (tep_db_num_rows($category_query)) {
                               $category = tep_db_fetch_array($category_query);

                               $categories = array();
                               $this->get_parent_categories($categories, $category['categories_id']);

                               $categories = array_reverse($categories);

                               $cPath = implode('_', $categories);

                               if (tep_not_null($cPath)) $cPath .= '_';
                               $cPath .= $category['categories_id'];
                       }

                       return $cPath;
               }

               function get_parent_categories(&$categories, $categories_id) {
                       $parent_categories_query = tep_db_query("select parent_id from " . TABLE_CATEGORIES . " where categories_id = '" . (int)$categories_id . "'");
                       while ($parent_categories = tep_db_fetch_array($parent_categories_query)) {
                               if ($parent_categories['parent_id'] == 0) return true;
                               $categories[sizeof($categories)] = $parent_categories['parent_id'];
                               if ($parent_categories['parent_id'] != $categories_id) {
                                       $this->get_parent_categories($categories, $parent_categories['parent_id']);
                               }
                       }
               }

               function get_products_special_price($product_id) {
               $customer_group_id = 0;
               $product_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . (int)$product_id . "' and customers_group_id = '" . (int)$customer_group_id . "'");
                       $product = tep_db_fetch_array($product_query);

                       return $product['specials_new_products_price'];
       }

               function break_string($s, $len) {
                       $tmp = explode(' ', substr(trim($s), 0, $len));
                       $tmp[count($tmp)-1] = '';

                       return implode(' ', $tmp);
               }
 }
?>
 
Bevor du hier jemand bittest kilometerweise Code für dich zu lesen, warum tauschst du das Programm nicht durch ein Skript aus und schreibst die Parameter in eine Datei?
 
Das ist ein PHP Script. Mehr Script geht da nicht. :D
Die CLI von PHP bietet eine Option dafür. Musste dir mal »man php« anschauen.

Weiß jetzt ausm Kopf leider nicht wie es ging.

//edit
@saeckereier Ach so meinst Du das... Das geht natürlich auch.

//edit2
Das ist ja einfach nur eine Klasse. Wie sieht denn der Aufruf der Klasse aus? Das müssen wir hier natürlich auch sehen.
 
Zuletzt bearbeitet:
Zur Verdeutlichung, da es anscheinend mißverständlich formuliert war:
Man kann das Programm, das durch das PHP-Skript aufgerufen wird, durch ein Shell-Skript ersetzen, das dann die Parameter mit denen es aufgerufen wird in eine Datei schreibt.
 

Ähnliche Themen

Problem mit HSPA+ Modem Huawei E353 - Installation unmöglich?

NagiosGrapher 1.7.1 funktioniert nicht

Samba 4 Gast Zugang unter Ubuntu funktioniert nicht

dovecot und postfix Konfiguration Problem

Windows clients können nicht mehr auf lange laufendes System zugreifen

Zurück
Oben