2012-03-29 8 views
2
<?php 
    require_once 'abstract.php'; 

    class Mage_Shell_Snapshot extends Mage_Shell_Abstract 
    { 
    public function _snapshot() 
    { 
     if(!Mage::isInstalled()) 
     { 
      echo "Application is not installed yet, please complete install wizard first."; 
      exit; 
     } 
     # Initialize configuration values 
     $connection = Mage::getConfig()->getNode('global/resources/default_setup /connection'); 
     $rootpath = $this->_getRootPath(); 
     $snapshot = $rootpath.'testing'; 

     # Create the snapshot directory if not exists 
     $io = new Varien_Io_File(); 
     $io->mkdir($snapshot); 

     include('/home/test/public_html/xmlapi.php'); 
     $cp_user="test"; 
     $cp_pass="test123"; 
     $db_host="localhost"; 
     $db_name="test_insatller"; 
     $db_user="test_test"; 
     $db_pass="home123"; 
     $url="http://201.40.548.550/testing/"; 
     $ad_user="admin"; 
     $ad_pass="sk12121"; 
     $ad_email="[email protected]"; 
     $xmlapi = new xmlapi($db_host); 
     $xmlapi->set_port(2083); 
     $xmlapi->password_auth($cp_user,$cp_pass); 
     $xmlapi->set_debug(1); 
     //create database 
     $xmlapi->api1_query($cp_user,"Mysql", "adddb", array($db_name)); 
     //create user 
     $xmlapi->api1_query($cp_user,"Mysql", "adduser", array($db_user,$db_pass)); 
     //add user to database 
     $xmlapi->api1_query($cp_user,"Mysql", "adduserdb", array($db_name,$db_user,'all')); 
     $command = '/home/indieste/public_html/function.sh '.$db_host.' '.$db_name.' '.$db_user.' '.$db_pass.' '.$url.' '.$ad_user.' '.$ad_pass.' '.$ad_email; 
     echo $command; 
     system($command); 
     Mage::log($command); 

    } 
    public function run() 
    { 
     if ($this->getArg('testing')) 
     { 
      $this->_snapshot(); 
     } 
     else 
     { 
      echo $this->usageHelp(); 
     } 
    } 

    public function usageHelp() 
    { 
     global $argv; 
     $self = basename($argv[0]); 

     USAGE; 
    } 
    } 
    $shell = new Mage_Shell_Snapshot(); 
    $shell->run(); 

私はmagento->shell->snapshot.phpというフォルダからsnapshot.phpを実行しても、それはデータベースとユーザーを作成していません。私はmagentoからbashシェルスクリプトを実行できますか?

xmlapi.phpを使用してcpanelにデータベースとユーザーを作成し、この実行function.shファイルを実行して、magentoをcpanelのルートディレクトリにインストールします。それは私にどんなタイプのエラーも与えていません。このコードは、magento?からbashシェルスクリプト(function.sh)を実行するのに十分ですか?

function.shファイルには、サーバからmagentoをダウンロードし、それを抽出して、hostname、hostpassword、dbname、dbuser、dbpassword、adminユーザ、adminパスワードを使用してcpanelのルートディレクトリにインストールするコマンドが含まれています。

magentoからシェルスクリプトを実行する関連リンクがあれば、plsが私に与えて、magentoからシェルスクリプトを実行する方法を教えてください。

答えて

2

シェルスクリプトは、2つの方法で任意のPHPアプリケーションから実行できます。

  1. スクリプトを実行するためにのexec()機能を使用してください。

  2. backticks (``)を使用し、ダンプで実行するコマンドを指定します。 例:

$変数= `の`のLS;バックティックの内側にある。

は、変数にlsの出力を与えます。

これはセキュリティの観点からは深刻な問題の1つなので、アプリケーションでこれを使用している場合は、必ずご確認ください。

+1

まだデータベースを作成できませんでしたが、スクリプトはexec()を使用して実行されています。ありがとう! – Stan

2

は記事を参照してください:
メーカーをインポートするためのシェルスクリプトを使用しています http://www.magentocommerce.com/wiki/how_to_-_import_manufacturers_or_any_other_option_attribute_set

これが役に立ちます。

+1

私はすでにそのコードを使用していますが、cpanelでデータベースを作成するのではなく、コマンドプロンプトを使用してこのコードからスクリプトを実行していません。 – Stan

関連する問題