Fixed gh-234 to insure that the FTP server option works. Added the server option to the JCB package backup area.

This commit is contained in:
2018-02-20 22:46:29 +02:00
parent ab88bd49a0
commit 9d64afe138
18 changed files with 685 additions and 427 deletions

View File

@ -318,37 +318,10 @@ class Compiler extends Infusion
// make sure we have the correct file
if (JFile::exists($xml_update_server_path) && isset($this->componentData->update_server))
{
// use FTP
if ($this->componentData->update_server_protocol == 1)
{
// get server details
if ($ftp = ComponentbuilderHelper::getServer((int) $this->componentData->update_server, 1))
{
// now move the file
if (!$ftp->store($xml_update_server_path, null))
{
$this->app->enqueueMessage(JText::sprintf('The <b>%s</b> file could not be moved to <b>%s</b> server.', $this->updateServerFileName . '.xml', $$ftp->remote_server_name[(int) $this->componentData->update_server]), 'Error');
}
// remove the local file
JFile::delete($xml_update_server_path);
// close the connection
$ftp->quit();
}
}
// use SFTP
elseif ($this->componentData->update_server_protocol == 2)
{
if ($sftp = ComponentbuilderHelper::getServer((int) $this->componentData->update_server, 2))
{
// now move the file
if (!$sftp->put($sftp->remote_server_path[(int) $this->componentData->update_server] . $this->updateServerFileName . '.xml', ComponentbuilderHelper::getFileContents($xml_update_server_path, null)))
{
$this->app->enqueueMessage(JText::sprintf('The <b>%s</b> file could not be moved to <b>%s</b> path on <b>%s</b> server.', $this->updateServerFileName . '.xml', $sftp->remote_server_path[(int) $this->componentData->update_server], $sftp->remote_server_name[(int) $this->componentData->update_server]), 'Error');
}
// remove the local file
JFile::delete($xml_update_server_path);
}
}
// move to server
ComponentbuilderHelper::moveToServer($xml_update_server_path, $this->updateServerFileName . '.xml', (int) $this->componentData->update_server, $this->componentData->update_server_protocol);
// remove the local file
JFile::delete($xml_update_server_path);
}
}
}
@ -519,32 +492,8 @@ class Compiler extends Infusion
// make sure we have the correct file
if (isset($this->componentData->sales_server))
{
// use FTP
if ($this->componentData->sales_server_protocol == 1)
{
if ($ftp = ComponentbuilderHelper::getServer((int) $this->componentData->sales_server, 1))
{
// now move the file
if (!$ftp->store($xml_update_server_path, $this->componentSalesName . '.zip'))
{
$this->app->enqueueMessage(JText::sprintf('The <b>%s</b> file could not be moved to <b>%s</b> server.', $this->componentSalesName . '.zip', $ftp->remote_server_name[(int) $this->componentData->sales_server]), 'Error');
}
// close the connection
$ftp->quit();
}
}
// use SFTP
elseif ($this->componentData->sales_server_protocol == 2)
{
if ($sftp = ComponentbuilderHelper::getServer((int) $this->componentData->sales_server, 2))
{
// now move the file
if (!$sftp->put($sftp->remote_server_path[(int) $this->componentData->sales_server] . $this->componentSalesName . '.zip', ComponentbuilderHelper::getFileContents($this->filepath, null)))
{
$this->app->enqueueMessage(JText::sprintf('The <b>%s</b> file could not be moved to <b>%s</b> path on <b>%s</b> server.', $this->componentSalesName . '.zip', $sftp->remote_server_path[(int) $this->componentData->sales_server], $sftp->remote_server_name[(int) $this->componentData->sales_server]), 'Error');
}
}
}
// move to server
ComponentbuilderHelper::moveToServer($this->filepath, $this->componentSalesName . '.zip', (int) $this->componentData->sales_server, $this->componentData->sales_server_protocol);
}
}
// remove the component folder since we are done

View File

@ -1953,6 +1953,49 @@ abstract class ComponentbuilderHelper
require_once JPATH_ADMINISTRATOR.'/components/com_componentbuilder/helpers/vendor/autoload.php';
}
/**
* Move File to Server
*
* @param string $localPath The local path to the file
* @param string $fileName The the actual file name
* @param int $serverID The server local id to use
* @param int $protocol The server protocol to use
* @param string $permission The permission validation area
*
* @return bool true on success
**/
public static function moveToServer($localPath, $fileName, $serverID, $protocol = null, $permission = 'core.export')
{
// get the server
if ($server = self::getServer( (int) $serverID, $protocol, $permission))
{
// use the FTP protocol
if (1 == $server->jcb_protocol)
{
// now move the file
if (!$server->store($localPath, $fileName))
{
JFactory::getApplication()->enqueueMessage(JText::sprintf('COM_COMPONENTBUILDER_THE_BSB_FILE_COULD_NOT_BE_MOVED_TO_BSB_SERVER', $fileName, $server->jcb_remote_server_name[(int) $serverID]), 'Error');
return false;
}
// close the connection
$server->quit();
}
// use the SFTP protocol
elseif (2 == $server->jcb_protocol)
{
// now move the file
if (!$server->put($server->jcb_remote_server_path[(int) $serverID] . $fileName, self::getFileContents($localPath, null)))
{
JFactory::getApplication()->enqueueMessage(JText::sprintf('COM_COMPONENTBUILDER_THE_BSB_FILE_COULD_NOT_BE_MOVED_TO_BSB_PATH_ON_BSB_SERVER', $fileName, $server->jcb_remote_server_path[(int) $serverID], $server->jcb_remote_server_name[(int) $serverID]), 'Error');
return false;
}
}
return true;
}
return false;
}
/**
* the SFTP objects
**/
@ -1972,8 +2015,13 @@ abstract class ComponentbuilderHelper
*
* @return object on success server object
**/
public static function getServer($serverID, $protocol, $permission = 'core.export')
public static function getServer($serverID, $protocol = null, $permission = 'core.export')
{
// if not protocol is given get it (sad I know)
if (!$protocol)
{
$protocol = self::getVar('server', (int) $serverID, 'id', 'protocol');
}
// return the server object
switch ($protocol)
{
@ -2016,6 +2064,8 @@ abstract class ComponentbuilderHelper
$server->port = (isset($server->port) && is_int($server->port) && $server->port > 0) ? $server->port : 22;
// open the connection
self::$sftp[$server->cache] = new phpseclib\Net\SFTP($server->host, $server->port);
// heads-up on protocol
self::$sftp[$server->cache]->jcb_protocol = 2; // SFTP <-- if called not knowing what type of protocol is being used
// now login based on authentication type
switch($server->authentication)
{
@ -2077,14 +2127,14 @@ abstract class ComponentbuilderHelper
if (isset(self::$sftp[$server->cache]) && self::checkObject(self::$sftp[$server->cache]))
{
// set the unique buckets
if (!isset(self::$sftp[$server->cache]->remote_server_name))
if (!isset(self::$sftp[$server->cache]->jcb_remote_server_name))
{
self::$sftp[$server->cache]->remote_server_name = array();
self::$sftp[$server->cache]->remote_server_path = array();
self::$sftp[$server->cache]->jcb_remote_server_name = array();
self::$sftp[$server->cache]->jcb_remote_server_path = array();
}
// always set the name and remote server path
self::$sftp[$server->cache]->remote_server_name[$serverID] = $server->name;
self::$sftp[$server->cache]->remote_server_path[$serverID] = (self::checkString($server->path) && $server->path !== '/') ? $server->path : '';
self::$sftp[$server->cache]->jcb_remote_server_name[$serverID] = $server->name;
self::$sftp[$server->cache]->jcb_remote_server_path[$serverID] = (self::checkString($server->path) && $server->path !== '/') ? $server->path : '';
// return the sftp object
return self::$sftp[$server->cache];
}
@ -2109,7 +2159,7 @@ abstract class ComponentbuilderHelper
if (isset(self::$ftp[$server->cache]) && self::$ftp[$server->cache] instanceof JClientFtp)
{
// always set the name and remote server path
self::$ftp[$server->cache]->remote_server_name[$serverID] = $server->name;
self::$ftp[$server->cache]->jcb_remote_server_name[$serverID] = $server->name;
// if still connected we are ready to go
if (self::$ftp[$server->cache]->isConnected())
{
@ -2162,13 +2212,15 @@ abstract class ComponentbuilderHelper
// check if we are connected
if (self::$ftp[$server->cache] instanceof JClientFtp && self::$ftp[$server->cache]->isConnected())
{
// heads-up on protocol
self::$ftp[$server->cache]->jcb_protocol = 1; // FTP <-- if called not knowing what type of protocol is being used
// set the unique buckets
if (!isset(self::$ftp[$server->cache]->remote_server_name))
if (!isset(self::$ftp[$server->cache]->jcb_remote_server_name))
{
self::$ftp[$server->cache]->remote_server_name = array();
self::$ftp[$server->cache]->jcb_remote_server_name = array();
}
// always set the name and remote server path
self::$ftp[$server->cache]->remote_server_name[$serverID] = $server->name;
self::$ftp[$server->cache]->jcb_remote_server_name[$serverID] = $server->name;
// return the FTP instance
return self::$ftp[$server->cache];
}