2012-10-20 30 views
2

我實際上設法爲我製作的插件和安裝腳本文件創建安裝zip,我將此代碼包含在安裝函數中以便將joomla中的文件夾中的某個文件複製到另一個目錄中。jFile:移動不會導致任何錯誤,但它無法移動文件

class plgVmCustomPayeddownloadsInstallerScript { 

    function install($parent) { 

     $src = "plugins/vmcustom/payeddownloads/payeddownloads.php"; 
     $destination = "components/com_virtuemart/controllers";  
     if(!JFile::move($src, $destination,JPATH_ROOT)){ 
      echo "tried to move from ".$src." to ".$destination; 
      return false; 
    } 
} 

我一直在的Joomla收到錯誤安裝完畢後,「無法重命名文件」,而應該被移動通過安裝功能命令沒有文件,儘管內的文件installation.xml確實得到了複製並正確安裝。

也在安裝腳本中在安裝函數中,我包含了一些正常執行沒有任何問題的SQL。

我也嘗試在postflight函數中沒有成功。 另外我沒有從php_error.log中得到任何特定的錯誤

我也嘗試創建這個奇怪的測試,在我的joomla安裝的根應用程序中的上述tester.php文件。

<?php 
/** 
* @package  Joomla.Site 
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved. 
* @license  GNU General Public License version 2 or later; see LICENSE.txt 
*/ 

// Set flag that this is a parent file. 
define('_JEXEC', 1); 
define('DS', DIRECTORY_SEPARATOR); 

if (file_exists(dirname(__FILE__) . '/defines.php')) { 
    include_once dirname(__FILE__) . '/defines.php'; 
} 

if (!defined('_JDEFINES')) { 
    define('JPATH_BASE', dirname(__FILE__)); 
    require_once JPATH_BASE.'/includes/defines.php'; 
} 

require_once JPATH_BASE.'/includes/framework.php'; 

// Mark afterLoad in the profiler. 
JDEBUG ? $_PROFILER->mark('afterLoad') : null; 

// Instantiate the application. 
$app = JFactory::getApplication('site'); 

// Initialise the application. 
$app->initialise(); 

// Mark afterIntialise in the profiler. 
JDEBUG ? $_PROFILER->mark('afterInitialise') : null; 

// Route the application. 
$app->route(); 

// Mark afterRoute in the profiler. 
JDEBUG ? $_PROFILER->mark('afterRoute') : null; 

// Dispatch the application. 
$app->dispatch(); 

// Mark afterDispatch in the profiler. 
JDEBUG ? $_PROFILER->mark('afterDispatch') : null; 

// Render the application. 
$app->render(); 

// Mark afterRender in the profiler. 
JDEBUG ? $_PROFILER->mark('afterRender') : null; 


    //plugins/vmcustom/payeddownloads/payeddownloads.php to 
    //components/com_virtuemart/controllers 
    jimport('joomla.filesystem.file'); 
    $src = JPATH_ROOT."/plugins/vmcustom/payeddownloads/payeddownloads.php"; 
    $destination = JPATH_ROOT."/components/com_virtuemart/controllers/";   
    echo $src."<br>"; 
    echo $destination."<br>"; 
    JFile::move($src,$destination); 

?> 

該文件沒有從payeddownloads移動到控制器文件夾,它不會導致任何錯誤。

另外我需要提及的是php.ini有error_reporting = E_ALL和display_errors = On。 此外php_error.log捕獲錯誤。如果我輸入例如echo「lala」oo,它會記錄錯誤並顯示它。 所以我懷疑JFile :: move有一個錯誤,即使該文件沒有被複制也不會拋出任何錯誤。有什麼建議嗎?

回答

1

請嘗試使用以下代替。一些調整,令代碼:

function install($parent) { 

    $src = JPATH_SITE . "/plugins/vmcustom/payeddownloads/payeddownloads.php"; 
    $destination = JPATH_SITE . "/components/com_virtuemart/controllers"; 

    if(JFile::exists($src)){ 
     echo "File Exists!"; 
    } 
    else{ 
     echo "File Doesn't Exist!"; 
    } 
    if(JFolder::exists($destination)){ 
     echo "Destination Folder Exists!"; 
    } 
    else{ 
     echo "Destination Folder Doesn't Exist!"; 
    } 

    JFile::move($src, $destination); // Move file 

    if(JFile::move($src, $destination)){ 
     echo "File Successfully Moved!"; 
    } 
    else{ 
     echo "failed to move from ".$src." to ".$destination; 
    } 

} 
+0

不,它不工作,沒有錯誤。我還添加了其他語句,並將其移至其他位置,例如它正在成功移動它。我也設法顯示隱藏的文件,以防萬一,但沒有:(它甚至沒有隱藏。 我也試過jFile :: copy,但是如果你失敗了,它會迴應試圖移動..。任何其他建議?thanx爲你提供幫助btw – themis

+0

我也做過,如果(!JFile :: exists($ src)){echo「文件不存在於$ src
」;}和它回聲,但我看到文件:(。我wana – themis

+1

@themhz :更新了我的答案,我想我應該記住你必須使用JPATH_SITE來定義移動文件時的路徑 – Lodder

0

甚至認爲線程是老了,我發現有同樣的問題,也許該解決方案可以爲任何人工作。

JFile :: move需要源文件路徑和目標文件路徑。在上面的代碼中,路徑應該如下所示。

$src = JPATH_SITE . "/plugins/vmcustom/payeddownloads/payeddownloads.php"; 
$destination = JPATH_SITE . "/components/com_virtuemart/controllers/payeddownloads.php";