first commit
This commit is contained in:
@@ -0,0 +1,751 @@
|
||||
<?php
|
||||
/**
|
||||
* SOTESHOP/stInstallerPlugin
|
||||
*
|
||||
* Ten plik należy do aplikacji stInstallerPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
|
||||
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
|
||||
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
|
||||
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
|
||||
*
|
||||
* @package stInstallerPlugin
|
||||
* @subpackage libs
|
||||
* @copyright SOTE (www.sote.pl)
|
||||
* @license http://www.sote.pl/license/open (Open License SOTE) Otwarta Licencja SOTE
|
||||
* @version $Id: stBaseFileManager.class.php 3782 2010-03-05 13:39:42Z marek $
|
||||
*/
|
||||
|
||||
/**
|
||||
* Rozszerzenie funkcjonalności klasy sfFinder
|
||||
*
|
||||
* @see sfFinder
|
||||
* @author Marcin Butlak <marcin.butlak@sote.pl>
|
||||
*
|
||||
* @package stInstallerPlugin
|
||||
* @subpackage libs
|
||||
*/
|
||||
class stFinder extends sfFinder
|
||||
{
|
||||
/**
|
||||
* Usuwa wszystkie kryteria filtrowania
|
||||
*
|
||||
* @return stFinder
|
||||
*/
|
||||
public function clear()
|
||||
{
|
||||
$this->discards = array();
|
||||
$this->prunes = array();
|
||||
$this->maxdepth = 1000;
|
||||
$this->mindepth = 0;
|
||||
$this->names = array();
|
||||
$this->sizes = array();
|
||||
$this->ignore_version_control();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwracaj ścieżki absolutne
|
||||
*/
|
||||
public function absolute()
|
||||
{
|
||||
$this->relative = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tworzy nowa instancje stFinder
|
||||
*
|
||||
* @param string $type typ wyświetlanych wyników ('any' - wszystkie pliki, 'dir' - tylko katalogi, 'file' - tylko pliki)
|
||||
* @return stFinder
|
||||
*/
|
||||
public static function create($type = 'file')
|
||||
{
|
||||
$finder = new self();
|
||||
|
||||
if (strtolower(substr($type, 0, 3)) == 'dir')
|
||||
{
|
||||
$finder->type = 'directory';
|
||||
}
|
||||
else
|
||||
if (strtolower($type) == 'any')
|
||||
{
|
||||
$finder->type = 'any';
|
||||
}
|
||||
else
|
||||
{
|
||||
$finder->type = 'file';
|
||||
}
|
||||
|
||||
return $finder;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Podstawowa klasa do obsługi operacji plikowych
|
||||
*
|
||||
* @author Marcin Butlak <marcin.butlak@sote.pl>
|
||||
* @verison $Id: stBaseFileManager.class.php 3782 2010-03-05 13:39:42Z marek $
|
||||
*
|
||||
* @package stInstallerPlugin
|
||||
* @subpackage libs
|
||||
*/
|
||||
abstract class stBaseFileManager
|
||||
{
|
||||
protected $protected_files = array();
|
||||
|
||||
/**
|
||||
* Instancja obiektu stFinder
|
||||
* @var stFinder
|
||||
*/
|
||||
protected $filter = null;
|
||||
|
||||
/**
|
||||
* Domyślne prawa ustalane na katalogi i pliki
|
||||
* @var array
|
||||
*/
|
||||
protected $perm = array('file' => 0644, 'dir' => 0755);
|
||||
|
||||
/**
|
||||
* Kopiuje plik lub pusty katalog (według ustalonych reguł filtru)
|
||||
* Zależne od systemu plików
|
||||
*
|
||||
* @param string $origin_path Ścieżka przenoszonego pliku
|
||||
* @param string $target_path Ścieżka docelowa przenoszonego pliku lub pustego katalogu
|
||||
* @param string $force_override
|
||||
*/
|
||||
abstract protected function _copy($origin_path, $target_path, $perm = null);
|
||||
|
||||
/**
|
||||
* Tworzy katalog o podanej ścieżce
|
||||
* Zależne od systemu plików
|
||||
*
|
||||
* @param string $path Ścieżka do katalogu
|
||||
*/
|
||||
abstract protected function _mkdir($path, $perm = null);
|
||||
|
||||
/**
|
||||
* Usuwa plik lub zawartość katalogu (według ustalonych reguł filtru)
|
||||
* Zależne od systemu plików
|
||||
*
|
||||
* @param string $file Ścieżka usuwanego pliku lub katalogu
|
||||
*/
|
||||
abstract protected function _remove($file);
|
||||
|
||||
/**
|
||||
* Synchronizuje katalogi
|
||||
*
|
||||
* @param string $origin_path Ścieżka synchronizowanego katalogu
|
||||
* @param string $target_path Ścieżka docelowa
|
||||
* @param string $sync_dir Ścieżka katalogu dla plików synchronizacji
|
||||
* @param string $disereg Wyrażenie regularne dla plików, ktore niegdy nie będą synchornizowane, fix do pomijania katalogów postaci stAppName/stAppName
|
||||
* @param array $ignore Lista wyrażeń regularnych dla ignorowanych plików.
|
||||
*/
|
||||
public function sync($origin_path, $target_path, $sync_dir, $force_override = false, $disereg = '', $ignore = array())
|
||||
{
|
||||
if (!is_dir($origin_path))
|
||||
{
|
||||
throw new Exception(sprintf("The path '%s' must be a directory...", $origin_path));
|
||||
}
|
||||
|
||||
$remove_list = array();
|
||||
|
||||
$file_list = array();
|
||||
|
||||
$files = $this->filter()->in($origin_path);
|
||||
|
||||
if ($disereg) {
|
||||
$files = stFileManagerFilter::diseregFilter($files, $disereg);
|
||||
}
|
||||
|
||||
$sync_file = $sync_dir . DIRECTORY_SEPARATOR . self::computeSyncNameFromPath($origin_path);
|
||||
|
||||
foreach ($files as $file)
|
||||
{
|
||||
$target_file = $target_path . $this->computeRelativePath($file, $origin_path);
|
||||
|
||||
$file_list[$file] = $target_file;
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (is_file($sync_file))
|
||||
{
|
||||
$target_files = file($sync_file, FILE_IGNORE_NEW_LINES);
|
||||
|
||||
$remove_list = array_diff($target_files, $file_list, $this->protected_files);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->_mkdir(dirname($sync_file));
|
||||
}
|
||||
|
||||
rsort($remove_list);
|
||||
|
||||
$this->remove($remove_list,null,$ignore);
|
||||
|
||||
foreach ($file_list as $file => $target_file)
|
||||
{
|
||||
$target_file = $target_path . $this->computeRelativePath($file, $origin_path);
|
||||
|
||||
if (!$this->isSync($file, $target_file) || $force_override)
|
||||
{
|
||||
$this->_mkdir(dirname($target_file));
|
||||
|
||||
// sprawdz czy mozna kopiowac plik, czy nie jest on na liscie plikow ignorowanych
|
||||
if (null === $ignore || (!stFileManagerFilter::ignoreFile($target_file,$ignore) && stFileManagerFilter::replaceFile($file, $target_file)))
|
||||
{
|
||||
$this->_copy($file, $target_file);
|
||||
}
|
||||
}
|
||||
|
||||
$this->protected_files[$file] = $target_file;
|
||||
}
|
||||
|
||||
file_put_contents($sync_file, implode("\n", $file_list));
|
||||
}
|
||||
|
||||
/**
|
||||
* Czyści nieistniejące katalogi synchronizacji
|
||||
*
|
||||
* @param string $origin_path ścieżka usuniętego katalogu źródłowego
|
||||
* @param string $sync_dir ścieżka katalogu
|
||||
*/
|
||||
public function syncClean($origin_path, $sync_dir)
|
||||
{
|
||||
$sync_file = $sync_dir . DIRECTORY_SEPARATOR . self::computeSyncNameFromPath($origin_path);
|
||||
|
||||
$filter = new stFileManagerFilter('any');
|
||||
|
||||
$filter->ignore_version_control()->name('*.sync')->maxdepth(0);
|
||||
|
||||
if (!file_exists($origin_path) && is_file($sync_file))
|
||||
{
|
||||
$files = file($sync_file, FILE_IGNORE_NEW_LINES);
|
||||
rsort($files);
|
||||
$this->remove($files, $filter);
|
||||
$this->remove($sync_file);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Kopiuje plik lub zawartość katalogu (według ustalonych reguł filtru)
|
||||
*
|
||||
* @param mixed $origin_path Ścieżka/Lista ścieżek kopiowanego pliku lub katalogu
|
||||
* @param string $target_path Ścieżka docelowa kopiowanego pliku lub katalogu
|
||||
* @param bool $force_override Określa wymuszenie nadpisania docelowego pliku
|
||||
* @param bool $act_as_move Określa czy funkcja ma przenosić plik (usuwać plik kopiowany)
|
||||
* @param integer $perm Domyślne prawa dla zapisywanego pliku (w przypadku podania null brane są prawa domyślne)
|
||||
*/
|
||||
public function copy($origin_path, $target_path, $force_override = false, $act_as_move = false, $perm = null)
|
||||
{
|
||||
if (is_string($origin_path))
|
||||
{
|
||||
$paths = array($origin_path);
|
||||
}
|
||||
elseif (is_array($origin_path))
|
||||
{
|
||||
$paths = $origin_path;
|
||||
}
|
||||
|
||||
rsort($paths);
|
||||
|
||||
foreach ($paths as $path)
|
||||
{
|
||||
$path = self::fixPath($path);
|
||||
|
||||
if (is_dir($path))
|
||||
{
|
||||
$files = $this->filter()->in($path);
|
||||
|
||||
rsort($files);
|
||||
|
||||
foreach ($files as $file)
|
||||
{
|
||||
$target_file = $target_path . $this->computeRelativePath($file, $path);
|
||||
|
||||
if (!$this->isSync($file, $target_file) || $force_override)
|
||||
{
|
||||
$this->mkdir(dirname($target_file), $perm);
|
||||
|
||||
if (!$this->_copy($file, $target_file, $perm))
|
||||
return false;
|
||||
|
||||
if ($act_as_move)
|
||||
{
|
||||
$this->_remove($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif (!$this->isSync($file, $target_path) || $force_override)
|
||||
{
|
||||
$this->mkdir(dirname($target_path), $perm);
|
||||
|
||||
if (!$this->_copy($origin_path, $target_path, $perm))
|
||||
return false;
|
||||
|
||||
if ($act_as_move)
|
||||
{
|
||||
$this->_remove($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function move($origin_path, $target_path, $force_override = false, $perm = null)
|
||||
{
|
||||
return $this->copy($origin_path, $target_path, $force_override, true, $perm);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tworzy katalog o podanej ścieżce
|
||||
*
|
||||
* @param string $path Ścieżka do katalogu
|
||||
* @param integer $perm Domyślne prawa dla zapisywanego pliku (w przypadku podania null brane są prawa domyślne)
|
||||
*/
|
||||
public function mkdir($path, $perm = null)
|
||||
{
|
||||
return $this->_mkdir($path, $perm);
|
||||
}
|
||||
|
||||
/**
|
||||
* Usuwa plik lub katalog wraz z jego zawartością (według ustalonych reguł filtru)
|
||||
*
|
||||
* @param string $target_path Ścieżka usuwanego pliku lub katalogu
|
||||
* @param stFileManagerFilter $filter Opcjonalny obiekt filtru (nadpisuje kryteria filtrów ustalonych za pomocą ->filter())
|
||||
* @param array lista plików ignorowanych
|
||||
*/
|
||||
public function remove($path, $filter = null, $ignore = null)
|
||||
{
|
||||
$paths = array();
|
||||
|
||||
if (is_array($path))
|
||||
{
|
||||
$paths = $path;
|
||||
}
|
||||
elseif (is_dir($path))
|
||||
{
|
||||
if (is_null($filter))
|
||||
{
|
||||
$filter = $this->filter();
|
||||
}
|
||||
|
||||
$paths = $filter->in(self::fixPath($path));
|
||||
$paths[] = $path;
|
||||
}
|
||||
elseif (is_file($path))
|
||||
{
|
||||
$paths = array($path);
|
||||
}
|
||||
|
||||
rsort($paths);
|
||||
|
||||
foreach ($paths as $path)
|
||||
{
|
||||
// sprawdz czy mozna usunac plik, czy nie jest on na liscie plikow ignorowanych
|
||||
// sprawdz czy mozna usunac plik, czy nie jest on na liscie plikow ignorowanych
|
||||
if (! stFileManagerFilter::ignoreFile(self::fixPath($path),$ignore))
|
||||
{
|
||||
$this->_remove(self::fixPath($path));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Zapisuje dane do pliku
|
||||
*
|
||||
* @param string $filename Scieżka zapisywanego pliku
|
||||
* @param mixed $data Dane do zapisania
|
||||
* @param bool $append Jeśli plik istnieje dopisuj do niego dane zamiast je nadpisywać
|
||||
* @param integer $perm Domyślne prawa dla zapisywanego pliku (w przypadku podania null brane są prawa domyślne)
|
||||
* @return bool W przypadku powodzenia zwraca ilość zapisanych bajtów w innym wypadku zwraca FALSE
|
||||
*/
|
||||
public function fileWrite($filename, $data, $append = false, $perm = null)
|
||||
{
|
||||
$bytes = @file_put_contents($filename, $data, $append ? FILE_APPEND : null);
|
||||
|
||||
if ($bytes)
|
||||
{
|
||||
$this->chmod($filename, $perm);
|
||||
}
|
||||
|
||||
return $bytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Odczytuje plik
|
||||
*
|
||||
* @param string $filename Scieżka odczytywanego pliku
|
||||
* @param bool $read_as_array Odczytaj w formie tablicy (działa identycznie jak file z włączoną flagą FILE_IGNORE_NEW_LINES)
|
||||
* @return mixed Odczytane dane
|
||||
*/
|
||||
public function fileRead($filename, $read_as_array)
|
||||
{
|
||||
if ($read_as_array)
|
||||
{
|
||||
return @file($filename, FILE_IGNORE_NEW_LINES);
|
||||
}
|
||||
|
||||
return @file_get_contents($filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwraca instancję filtru
|
||||
*
|
||||
* @return stFileManagerFilter
|
||||
*/
|
||||
public function filter()
|
||||
{
|
||||
if (is_null($this->filter))
|
||||
{
|
||||
$this->filter = new stFileManagerFilter('any');
|
||||
}
|
||||
|
||||
return $this->filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ustawia domyslne uprawnienia dla plików i katalogów wykorzystywane podczas operacji tworzenia, zapisywania, przenoszenia itp.
|
||||
*
|
||||
* @param integer $file Ustawia prawa dla plików (w przypadku podania null brane są poprzednio ustawione prawa)
|
||||
* @param integer $dir Ustawia prawa dla katalogów (w przypadku podania null brane są poprzednio ustawione prawa)
|
||||
*/
|
||||
public function setPermissions($file = null, $dir = null)
|
||||
{
|
||||
if ($file)
|
||||
{
|
||||
$this->perm['file'] = $file;
|
||||
}
|
||||
|
||||
if ($dir)
|
||||
{
|
||||
$this->perm['dir'] = $dir;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ustala uprawnienia dla plików lub katalogów
|
||||
*
|
||||
* @param string $filename Ścieżka do pliku lub katalogu
|
||||
* @param integer $perm Prawa (w przypadku podania null brane są prawa domyślne)
|
||||
*/
|
||||
public function chmod($filename, $perm = null)
|
||||
{
|
||||
if (is_null($perm))
|
||||
{
|
||||
$perm = is_dir($filename) ? $this->perm['dir'] : $this->perm['file'];
|
||||
}
|
||||
|
||||
return chmod($filename, $perm);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sprawdza synchronizację pliku źródłowego z plikiem docelowym
|
||||
*
|
||||
* @param string $origin_file Ścieżka pliku źródłowego
|
||||
* @param string $target_file Ścieżka pliku docelowego
|
||||
* @return bool
|
||||
*/
|
||||
protected function isSync($origin_file, $target_file)
|
||||
{
|
||||
$is_sync = false;
|
||||
|
||||
if (file_exists($target_file))
|
||||
{
|
||||
$stat_target = stat($target_file);
|
||||
|
||||
$stat_origin = stat($origin_file);
|
||||
|
||||
$is_sync = ($stat_origin['mtime'] > $stat_target['mtime']) ? false : true;
|
||||
}
|
||||
|
||||
return $is_sync;
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwraca scieżke relatywną dla podanego pliku
|
||||
*
|
||||
* @param string $origin_file Ścieżka do pliku
|
||||
* @param string $origin_root Ścieżka od której ma zostać utworzona ścieżka relatywna dla pliku
|
||||
* @return string scieżka relatywna
|
||||
*/
|
||||
protected function computeRelativePath($origin_file, $origin_root)
|
||||
{
|
||||
if (stripos($origin_file, $origin_root) !== 0)
|
||||
{
|
||||
throw new Exception(sprintf("File: '%s' must be within the origin root path '%s'", $origin_file, $origin_root));
|
||||
}
|
||||
|
||||
return substr($origin_file, strlen($origin_root));
|
||||
}
|
||||
|
||||
/**
|
||||
* Zamienia ścieżkę katalogu źródłowego na nazwę pliku synchronizacji
|
||||
*
|
||||
* @param string $path ścieżka do katalogu źródłowego
|
||||
* @return string nazwa pliku synchronizacji
|
||||
*/
|
||||
public static function computeSyncNameFromPath($path)
|
||||
{
|
||||
return urlencode($path) . '.sync';
|
||||
}
|
||||
|
||||
/**
|
||||
* Zamienia nazwę pliku synchronizacji na ścieżkę katalogu źródłowego
|
||||
*
|
||||
* @param string $sync_name Nazwa pliku lub pełna scieżka
|
||||
* @return string ścieżka do katalogu źródłowego
|
||||
*/
|
||||
public static function computePathFromSyncName($sync_name)
|
||||
{
|
||||
return urldecode(basename($sync_name, '.sync'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Naprawia ścieżke do katalogu lub pliku
|
||||
* Zamienia separator katalogów na prawidłowy DIRECTORY_SEPARATOR i usuwa ostatni separator w przypadku scieżki do katalogu
|
||||
*
|
||||
* @param string $path
|
||||
* @return unknown
|
||||
*/
|
||||
public static function fixPath($path)
|
||||
{
|
||||
$path = strtr($path, '\\', DIRECTORY_SEPARATOR);
|
||||
$path = strtr($path, '/', DIRECTORY_SEPARATOR);
|
||||
return rtrim($path, DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper klasy stFinder dla stBaseFileManager
|
||||
*
|
||||
* @author Marcin Butlak <marcin.butlak@sote.pl>
|
||||
* @verison $Id: stBaseFileManager.class.php 3782 2010-03-05 13:39:42Z marek $
|
||||
*
|
||||
* @package stInstallerPlugin
|
||||
* @subpackage libs
|
||||
*/
|
||||
class stFileManagerFilter
|
||||
{
|
||||
/**
|
||||
* Instancja obiektu stFinder
|
||||
* @var stFinder
|
||||
*/
|
||||
protected $finder;
|
||||
|
||||
public function __construct($type = 'file')
|
||||
{
|
||||
$this->finder = stFinder::create($type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ustawia maksymalny poziom zagłębienia
|
||||
*
|
||||
* @param integer level Pozion zagłębienia
|
||||
* @return stFileManagerFilter
|
||||
*/
|
||||
public function maxdepth($level)
|
||||
{
|
||||
$this->finder->maxdepth($level);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ustawia minimalny poziom zagłębienia od którego będą zwracane wyniki.
|
||||
*
|
||||
* @param integer level Pozion zagłębienia
|
||||
* @return stFileManagerFiltert
|
||||
*/
|
||||
public function mindepth($level)
|
||||
{
|
||||
$this->finder->mindepth($level);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dodaje kryteria filtrowania plików (tylko pasujące pliki)
|
||||
* $file_manager_filter->name('*.php') <- tylko pliki o rozszerzeniu .php
|
||||
* $file_manager_filter->name('*test.php') <- tylko pliki ktorych nazwa kończy się na test.php
|
||||
* $file_manager_filter->name('test.php') <- tylko pliki o nazwie test.php
|
||||
*
|
||||
* @param list Lista parametrów lub prosty string
|
||||
* @return stFileManagerFilter
|
||||
*/
|
||||
public function name()
|
||||
{
|
||||
$args = func_get_args();
|
||||
|
||||
call_user_func_array(array($this->finder, 'name'), $args);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Odrzuca katalogi o podanych nazwach
|
||||
*
|
||||
* @param list Lista parametrów lub prosty string
|
||||
* @return stFileManagerFilter
|
||||
*/
|
||||
public function discard()
|
||||
{
|
||||
$args = func_get_args();
|
||||
|
||||
call_user_func_array(array($this->finder, 'discard'), $args);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dodaje kryteria filtrowania nazw katalogów (blokuje dalsze wyszkuwanie w podanych katalogach)
|
||||
*
|
||||
* @param list Lista parametrów lub prosty string
|
||||
* @return stFileManagerFilter
|
||||
*/
|
||||
public function prune()
|
||||
{
|
||||
$args = func_get_args();
|
||||
|
||||
call_user_func_array(array($this->finder, 'prune'), $args);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dodaje kryteria filtrowania plików (odrzuca pasujące pliki)
|
||||
*
|
||||
* @see ->name()
|
||||
* @param list Lista parametrów lub prosty string
|
||||
* @return stFileManagerFilter
|
||||
*/
|
||||
public function not_name()
|
||||
{
|
||||
$args = func_get_args();
|
||||
|
||||
call_user_func_array(array($this->finder, 'not_name'), $args);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ignoruj katalogi podlegające kontroli wersji (.svn, CVS itp)
|
||||
*
|
||||
* @return stFileManagerFilter
|
||||
*/
|
||||
public function ignore_version_control()
|
||||
{
|
||||
$this->finder->ignore_version_control();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwraca listę plików lib katalogów spełniających ustalone kryteria filtrowania
|
||||
*
|
||||
* @param Lista katalogów zawierających pliki
|
||||
*/
|
||||
public function in()
|
||||
{
|
||||
return $this->finder->in(func_get_args());
|
||||
}
|
||||
|
||||
/**
|
||||
* Filtruje listę wyszukanych plików wg wyrażeń regularnych.
|
||||
* Filtr dotyczy nazwy i ścieżki do pliku.
|
||||
*
|
||||
* @param array $files Lista plikow.
|
||||
* @param string $disereg Wyrażenie regularne określające, które pliki będą pomijane.
|
||||
* @return array Lista plików.
|
||||
*/
|
||||
static public function diseregFilter($files, $disereg)
|
||||
{
|
||||
if (empty($disereg))
|
||||
return $files;
|
||||
$d = array();
|
||||
foreach ($files as $file)
|
||||
{
|
||||
if (strpos($file, $disereg) === false) // poprawka synchronizacji dla Windows (michal.prochowski@sote.pl)
|
||||
$d[] = $file;
|
||||
}
|
||||
return $d;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sprawdza czy dany plik można skopiować.
|
||||
* Jeśli plik jest oznaczony jako ignoroany to przy synchronizacji jeśli taki plik istnieje, to nie jest nadrgywany.
|
||||
*
|
||||
* @param array $files Lista plikow.
|
||||
* @param array $ignore Wyrażenia regularne określające, które pliki będą pomijane. array('ereg'=>(ignore|discard))
|
||||
* ignore - plik pomijany w aktualizacji, discard - zawsze
|
||||
* @return bool true - plik jest ignorowany, false w p.w.
|
||||
*/
|
||||
static public function ignoreFile($file, $ignores) {
|
||||
if ($ignores)
|
||||
foreach ($ignores as $ignore)
|
||||
if (strpos($file, $ignore) !== false)
|
||||
if ((is_file($file)) && (file_exists($file))) {
|
||||
echo '[~ skip] $file'."\n";
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function replaceFile($sourcefile, $targetFile)
|
||||
{
|
||||
if (file_exists($targetFile) && is_file($targetFile))
|
||||
{
|
||||
list($shopPath, $filePath) = explode('install/src/', $sourcefile, 2);
|
||||
list($appName) = explode('/', $filePath, 2);
|
||||
|
||||
$file = str_replace($shopPath, '', $targetFile);
|
||||
|
||||
foreach (stInstallerIgnore::getIgnoreReplace($appName) as $pattern)
|
||||
{
|
||||
if (preg_match($pattern, $file))
|
||||
{
|
||||
$regFiles = self::loadLastRegFilelist($appName);
|
||||
|
||||
if (!empty($regFiles))
|
||||
{
|
||||
foreach($regFiles as $regFile => $regData)
|
||||
{
|
||||
if (str_replace($appName.'/'.$appName.'/', $appName.'/', $filePath) == $regFile)
|
||||
{
|
||||
if ($regData['md5sum'] != md5_file($targetFile)) return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static private $loadedLastRegApplication = null;
|
||||
static private $loadedLastRegFilelist = array();
|
||||
|
||||
public static function loadLastRegFilelist($appName)
|
||||
{
|
||||
if (self::$loadedLastRegApplication == $appName) return self::$loadedLastRegFilelist;
|
||||
else {
|
||||
self::$loadedLastRegApplication = $appName;
|
||||
self::$loadedLastRegFilelist = array();
|
||||
|
||||
$file = sfConfig::get('sf_root_dir').DIRECTORY_SEPARATOR.'install'.DIRECTORY_SEPARATOR.'db'.DIRECTORY_SEPARATOR.'.md5sum'.DIRECTORY_SEPARATOR.strtolower($appName).'.reg';
|
||||
if(file_exists($file))
|
||||
{
|
||||
$data = unserialize(file_get_contents($file));
|
||||
if (isset($data['filelist']))
|
||||
{
|
||||
self::$loadedLastRegFilelist = $data['filelist'];
|
||||
unset($data);
|
||||
}
|
||||
}
|
||||
return self::$loadedLastRegFilelist;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/**
|
||||
* SOTESHOP/stInstallerPlugin
|
||||
*
|
||||
* Ten plik należy do aplikacji stInstallerPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
|
||||
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
|
||||
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
|
||||
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
|
||||
*
|
||||
* @package stInstallerPlugin
|
||||
* @subpackage libs
|
||||
* @copyright SOTE (www.sote.pl)
|
||||
* @license http://www.sote.pl/license/open (Open License SOTE) Otwarta Licencja SOTE
|
||||
* @version $Id: stFtpFileManager.class.php 3782 2010-03-05 13:39:42Z marek $
|
||||
*/
|
||||
|
||||
/**
|
||||
* Obsługa operacji plikowych przez FTP (WWW).
|
||||
*
|
||||
* @author Marek Jakubowicz
|
||||
*
|
||||
* @package stInstallerPlugin
|
||||
* @subpackage libs
|
||||
*/
|
||||
class stFtpFileManager extends stBaseFileManager
|
||||
{
|
||||
protected static $instance = null;
|
||||
|
||||
/**
|
||||
* Kopiuje plik
|
||||
*
|
||||
* @param string $origin_path Ścieżka przenoszonego pliku
|
||||
* @param string $target_path Ścieżka docelowa przenoszonego pliku
|
||||
* @param string $force_override
|
||||
*/
|
||||
protected function _copy($origin_path, $target_path)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tworzy katalog o podanej ścieżce
|
||||
*
|
||||
* @param string $path Ścieżka do katalogu
|
||||
*/
|
||||
protected function _mkdir($path)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Usuwa plik lub katalog
|
||||
*
|
||||
* @param string $file Ścieżka usuwanego pliku lub katalogu
|
||||
*/
|
||||
protected function _remove($file)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function silentMode()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function verboseMode()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Pobiera instancje obiektu stFileManager
|
||||
*
|
||||
* @param $filter_type Typ filtru (any - dowolny plik, directory - tylko katalogi, file - tylko pliki)
|
||||
* @return stPakeFileManager
|
||||
*/
|
||||
public static function getInstance()
|
||||
{
|
||||
if (is_null(self::$instance))
|
||||
{
|
||||
self::$instance = new self();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
/**
|
||||
* SOTESHOP/stInstallerPlugin
|
||||
*
|
||||
* Ten plik należy do aplikacji stInstallerPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
|
||||
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
|
||||
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
|
||||
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
|
||||
*
|
||||
* @package stInstallerPlugin
|
||||
* @subpackage libs
|
||||
* @copyright SOTE (www.sote.pl)
|
||||
* @license http://www.sote.pl/license/open (Open License SOTE) Otwarta Licencja SOTE
|
||||
* @version $Id: stPakeFileManager.class.php 3782 2010-03-05 13:39:42Z marek $
|
||||
*/
|
||||
|
||||
/**
|
||||
* Obsługa operacji plikowych dla konsoli
|
||||
*
|
||||
* @author Marcin Butlak <marcin.butlak@sote.pl>
|
||||
*
|
||||
* @package stInstallerPlugin
|
||||
* @subpackage libs
|
||||
*/
|
||||
class stPakeFileManager extends stBaseFileManager
|
||||
{
|
||||
protected static $instance = null;
|
||||
|
||||
/**
|
||||
* Kopiuje plik
|
||||
*
|
||||
* @param string $origin_path Ścieżka przenoszonego pliku
|
||||
* @param string $target_path Ścieżka docelowa przenoszonego pliku
|
||||
* @param string $force_override
|
||||
*/
|
||||
protected function _copy($origin_path, $target_path, $perm = null)
|
||||
{
|
||||
if (is_dir($origin_path))
|
||||
{
|
||||
pake_mkdirs($target_path);
|
||||
}
|
||||
else if (is_file($origin_path))
|
||||
{
|
||||
pake_copy($origin_path, $target_path, array('override' => true));
|
||||
}
|
||||
else if (is_link($origin_path))
|
||||
{
|
||||
pake_symlink($origin_path, $target_path);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new pakeException(sprintf('Unable to determine "%s" type', $origin_path));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tworzy katalog o podanej ścieżce
|
||||
*
|
||||
* @param string $path Ścieżka do katalogu
|
||||
*/
|
||||
protected function _mkdir($path, $perm = null)
|
||||
{
|
||||
pake_mkdirs($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Usuwa plik lub katalog
|
||||
*
|
||||
* @param string $file Ścieżka usuwanego pliku lub katalogu
|
||||
*/
|
||||
protected function _remove($file)
|
||||
{
|
||||
if (is_link($file))
|
||||
{
|
||||
pake_echo_comment(sprintf('Path "%s" is a symlink - ignoring...', $file));
|
||||
}
|
||||
elseif (is_dir($file))
|
||||
{
|
||||
pake_echo_action('dir-', $file);
|
||||
|
||||
if (!@rmdir($file))
|
||||
{
|
||||
pake_echo_comment(sprintf('Directory "%s" not empty - ignoring...', $file));
|
||||
}
|
||||
} else
|
||||
{
|
||||
pake_echo_action('file-', $file);
|
||||
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
|
||||
public function silentMode()
|
||||
{
|
||||
pakeApp::get_instance()->handle_options('--quiet');
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function verboseMode()
|
||||
{
|
||||
pakeApp::get_instance()->handle_options('--verbose');
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pobiera instancje obiektu stFileManager
|
||||
*
|
||||
* @return stPakeFileManager
|
||||
*/
|
||||
public static function getInstance()
|
||||
{
|
||||
if (is_null(self::$instance))
|
||||
{
|
||||
self::$instance = new self();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
/**
|
||||
* SOTESHOP/stInstallerPlugin
|
||||
*
|
||||
* Ten plik należy do aplikacji stInstallerPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
|
||||
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
|
||||
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
|
||||
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
|
||||
*
|
||||
* @package stInstallerPlugin
|
||||
* @subpackage libs
|
||||
* @copyright SOTE (www.sote.pl)
|
||||
* @license http://www.sote.pl/license/open (Open License SOTE) Otwarta Licencja SOTE
|
||||
* @version $Id: stWebFileManager.class.php 3782 2010-03-05 13:39:42Z marek $
|
||||
*/
|
||||
|
||||
/**
|
||||
* Obsługa operacji plikowych dla WWW.
|
||||
*
|
||||
* @author Marek Jakubowicz
|
||||
*
|
||||
* @package stInstallerPlugin
|
||||
* @subpackage libs
|
||||
*/
|
||||
class stWebFileManager extends stBaseFileManager
|
||||
{
|
||||
protected static $instance = null;
|
||||
|
||||
/**
|
||||
* Kopiuje plik
|
||||
*
|
||||
* @param string $origin_path Ścieżka przenoszonego pliku
|
||||
* @param string $target_path Ścieżka docelowa przenoszonego pliku
|
||||
*/
|
||||
protected function _copy($origin_path, $target_path, $perm = null)
|
||||
{
|
||||
$ret = true;
|
||||
|
||||
if (is_file($origin_path))
|
||||
{
|
||||
$ret = @copy($origin_path, $target_path);
|
||||
}
|
||||
elseif (is_dir($origin_path))
|
||||
{
|
||||
$this->_mkdir($target_path, $perm);
|
||||
}
|
||||
|
||||
if ($ret)
|
||||
{
|
||||
$this->chmod($target_path, $perm);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tworzy katalog o podanej ścieżce
|
||||
*
|
||||
* @param string $path Ścieżka do katalogu
|
||||
*/
|
||||
protected function _mkdir($path, $perm = null)
|
||||
{
|
||||
if (is_null($perm))
|
||||
{
|
||||
$perm = $this->perm['dir'];
|
||||
}
|
||||
|
||||
return @mkdir($path, $perm, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Usuwa plik lub katalog
|
||||
*
|
||||
* @param string $file Ścieżka usuwanego pliku lub katalogu
|
||||
*/
|
||||
protected function _remove($file)
|
||||
{
|
||||
if (is_dir($file))
|
||||
{
|
||||
return @rmdir($file);
|
||||
}
|
||||
elseif (!is_link($file))
|
||||
{
|
||||
return @unlink($file);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function silentMode()
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function verboseMode()
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pobiera instancje obiektu stFileManager
|
||||
*
|
||||
* @return stPakeFileManager
|
||||
*/
|
||||
public static function getInstance()
|
||||
{
|
||||
if (is_null(self::$instance))
|
||||
{
|
||||
self::$instance = new self();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
}
|
||||
|
||||
86
plugins/stInstallerPlugin/lib/helper/stArrayHelper.php
Normal file
86
plugins/stInstallerPlugin/lib/helper/stArrayHelper.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/**
|
||||
* SOTESHOP/stInstallerPlugin
|
||||
*
|
||||
* Ten plik należy do aplikacji stInstallerPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
|
||||
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
|
||||
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
|
||||
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
|
||||
*
|
||||
* @package stInstallerPlugin
|
||||
* @subpackage helpers
|
||||
* @copyright SOTE (www.sote.pl)
|
||||
* @license http://www.sote.pl/license/open (Open License SOTE) Otwarta Licencja SOTE
|
||||
* @version $Id: stArrayHelper.php 3782 2010-03-05 13:39:42Z marek $
|
||||
* @author Marek Jakubowicz <marek.jakubowicz@sote.pl>
|
||||
*/
|
||||
|
||||
/**
|
||||
* Łączy 2 tablice, nadpisując powtarzające się klucze.
|
||||
* W wersji array_recursive_merge2 funkcja powielala wartosci dla kluczy liczbowych. Wersja 3 nie powtarza tych wartosci.
|
||||
*
|
||||
* @author felix dot ospald at gmx dot de
|
||||
* @author Marek jakubowicz <marek.jakubowicz@sote.pl
|
||||
* @see http://pl.php.net/manual/pl/function.array-merge-recursive.php
|
||||
*/
|
||||
function st_array_merge_recursive3($array1, $array2)
|
||||
{
|
||||
$arrays = func_get_args();
|
||||
$narrays = count($arrays);
|
||||
|
||||
// check arguments
|
||||
// comment out if more performance is necessary (in this case the foreach loop will trigger a warning if the argument is not an array)
|
||||
for ($i = 0; $i < $narrays; $i ++) {
|
||||
if (!is_array($arrays[$i])) {
|
||||
// also array_merge_recursive returns nothing in this case
|
||||
trigger_error('Argument #' . ($i+1) . ' is not an array - trying to merge array with scalar! Returning null!', E_USER_WARNING);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// the first array is in the output set in every case
|
||||
$ret = $arrays[0];
|
||||
|
||||
// merege $ret with the remaining arrays
|
||||
for ($i = 1; $i < $narrays; $i ++) {
|
||||
foreach ($arrays[$i] as $key => $value) {
|
||||
if (is_array($value) && isset($ret[$key])) {
|
||||
// if $ret[$key] is not an array you try to merge an scalar value with an array - the result is not defined (incompatible arrays)
|
||||
// in this case the call will trigger an E_USER_WARNING and the $ret[$key] will be null.
|
||||
$ret[$key] = st_array_merge_recursive3($ret[$key], $value);
|
||||
}
|
||||
else {
|
||||
$ret[$key] = $value;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwraca różnicę między 2 tablicami 1 wymiarowymi.
|
||||
*
|
||||
* @param array $dat1
|
||||
* @param array $dat2
|
||||
* @return array array('added'=>array(), 'changed'=>array(), 'deleted'=>array(), 'all'=>array())
|
||||
*/
|
||||
function st_array_diff($dat1, $dat2)
|
||||
{
|
||||
$added=array();$changed=array();$deleted=array(); $all=array();
|
||||
foreach ($dat2 as $key=>$val)
|
||||
{
|
||||
if (empty($dat1[$key])) { $added[]=$key; $all[]=$key; }
|
||||
elseif ($dat1[$key]!=$val) { $changed[]=$key; $all[]=$key; }
|
||||
}
|
||||
|
||||
foreach ($dat1 as $key=>$val)
|
||||
{
|
||||
if (empty($dat2[$key])) { $deleted[]=$key; $all[]=$key; }
|
||||
}
|
||||
|
||||
return array("added"=>$added,"changed"=>$changed,"deleted"=>$deleted,"all"=>$all);
|
||||
}
|
||||
?>
|
||||
410
plugins/stInstallerPlugin/lib/output/ProgressBar.class.php
Normal file
410
plugins/stInstallerPlugin/lib/output/ProgressBar.class.php
Normal file
@@ -0,0 +1,410 @@
|
||||
<?php
|
||||
// Copyright (c) 2007 Stefan Walk
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
|
||||
|
||||
// Authors: Stefan Walk <et@php.net>
|
||||
|
||||
/**
|
||||
* SOTESHOP/stInstallerPlugin
|
||||
*
|
||||
* Ten plik należy do aplikacji stInstallerPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
|
||||
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
|
||||
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
|
||||
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
|
||||
*
|
||||
* @package stInstallerPlugin
|
||||
* @subpackage libs
|
||||
* @copyright SOTE (www.sote.pl)
|
||||
* @license http://www.sote.pl/license/open (Open License SOTE) Otwarta Licencja SOTE
|
||||
* @version $Id: ProgressBar.class.php 3782 2010-03-05 13:39:42Z marek $
|
||||
* @author Stefan Walk <et@php.net>
|
||||
*/
|
||||
|
||||
class Console_ProgressBar {
|
||||
|
||||
// properties {{{
|
||||
/**
|
||||
* Skeleton for use with sprintf
|
||||
*/
|
||||
var $_skeleton;
|
||||
/**
|
||||
* The bar gets filled with this
|
||||
*/
|
||||
var $_bar;
|
||||
/**
|
||||
* The width of the bar
|
||||
*/
|
||||
var $_blen;
|
||||
/**
|
||||
* The total width of the display
|
||||
*/
|
||||
var $_tlen;
|
||||
/**
|
||||
* The position of the counter when the job is `done'
|
||||
*/
|
||||
var $_target_num;
|
||||
/**
|
||||
* Options, like the precision used to display the numbers
|
||||
*/
|
||||
var $_options = array();
|
||||
/**
|
||||
* Length to erase
|
||||
*/
|
||||
var $_rlen = 0;
|
||||
/**
|
||||
* When the progress started
|
||||
*/
|
||||
var $_start_time = null;
|
||||
var $_rate_datapoints = array();
|
||||
/**
|
||||
* Time when the bar was last drawn
|
||||
*/
|
||||
var $_last_update_time = 0.0;
|
||||
// }}}
|
||||
|
||||
// constructor() {{{
|
||||
/**
|
||||
* Constructor, sets format and size
|
||||
* See the reset() method for documentation.
|
||||
*
|
||||
* @param string The format string
|
||||
* @param string The string filling the progress bar
|
||||
* @param string The string filling empty space in the bar
|
||||
* @param integer The width of the display
|
||||
* @param float The target number for the bar
|
||||
* @param array Options for the progress bar
|
||||
* @see reset
|
||||
*/
|
||||
public function __construct($formatstring, $bar, $prefill, $width,
|
||||
$target_num, $options = array())
|
||||
{
|
||||
$this->reset($formatstring, $bar, $prefill, $width, $target_num,
|
||||
$options);
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ reset($formatstring, $bar, $prefill, $width, $target_num[, $options])
|
||||
/**
|
||||
* Re-sets format and size.
|
||||
* <pre>
|
||||
* The reset method expects 5 to 6 arguments:
|
||||
* - The first argument is the format string used to display the progress
|
||||
* bar. It may (and should) contain placeholders that the class will
|
||||
* replace with information like the progress bar itself, the progress in
|
||||
* percent, and so on. Current placeholders are:
|
||||
* %bar% The progress bar
|
||||
* %current% The current value
|
||||
* %max% The maximum malue (the "target" value)
|
||||
* %fraction% The same as %current%/%max%
|
||||
* %percent% The status in percent
|
||||
* %elapsed% The elapsed time
|
||||
* %estimate% An estimate of how long the progress will take
|
||||
* More placeholders will follow. A format string like:
|
||||
* "* stuff.tar %fraction% KB [%bar%] %percent%"
|
||||
* will lead to a bar looking like this:
|
||||
* "* stuff.tar 391/900 KB [=====>---------] 43.44%"
|
||||
* - The second argument is the string that is going to fill the progress
|
||||
* bar. In the above example, the string "=>" was used. If the string you
|
||||
* pass is too short (like "=>" in this example), the leftmost character
|
||||
* is used to pad it to the needed size. If the string you pass is too long,
|
||||
* excessive characters are stripped from the left.
|
||||
* - The third argument is the string that fills the "empty" space in the
|
||||
* progress bar. In the above example, that would be "-". If the string
|
||||
* you pass is too short (like "-" in this example), the rightmost
|
||||
* character is used to pad it to the needed size. If the string you pass
|
||||
* is too short, excessive characters are stripped from the right.
|
||||
* - The fourth argument specifies the width of the display. If the options
|
||||
* are left untouched, it will tell how many characters the display should
|
||||
* use in total. If the "absolute_width" option is set to false, it tells
|
||||
* how many characters the actual bar (that replaces the %bar%
|
||||
* placeholder) should use.
|
||||
* - The fifth argument is the target number of the progress bar. For
|
||||
* example, if you wanted to display a progress bar for a download of a
|
||||
* file that is 115 KB big, you would pass 115 here.
|
||||
* - The sixth argument optional. If passed, it should contain an array of
|
||||
* options. For example, passing array('absolute_width' => false) would
|
||||
* set the absolute_width option to false. Current options are:
|
||||
* option | def. | meaning
|
||||
* --------------------------------------------------------------------
|
||||
* percent_precision | 2 | Number of decimal places to show when
|
||||
* | | displaying the percentage.
|
||||
* fraction_precision | 0 | Number of decimal places to show when
|
||||
* | | displaying the current or target
|
||||
* | | number.
|
||||
* percent_pad | ' ' | Character to use when padding the
|
||||
* | | percentage to a fixed size. Senseful
|
||||
* | | values are ' ' and '0', but any are
|
||||
* | | possible.
|
||||
* fraction_pad | ' ' | Character to use when padding max and
|
||||
* | | current number to a fixed size.
|
||||
* | | Senseful values are ' ' and '0', but
|
||||
* | | any are possible.
|
||||
* width_absolute | true | If the width passed as an argument
|
||||
* | | should mean the total size (true) or
|
||||
* | | the width of the bar alone.
|
||||
* ansi_terminal | false | If this option is true, a better
|
||||
* | | (faster) method for erasing the bar is
|
||||
* | | used. CAUTION - this is known to cause
|
||||
* | | problems with some terminal emulators,
|
||||
* | | for example Eterm.
|
||||
* ansi_clear | false | If the bar should be cleared everytime
|
||||
* num_datapoints | 5 | How many datapoints to use to create
|
||||
* | | the estimated remaining time
|
||||
* min_draw_interval | 0.0 | If the last call to update() was less
|
||||
* | | than this amount of seconds ago,
|
||||
* | | don't update.
|
||||
* </pre>
|
||||
*
|
||||
* @param string The format string
|
||||
* @param string The string filling the progress bar
|
||||
* @param string The string filling empty space in the bar
|
||||
* @param integer The width of the display
|
||||
* @param float The target number for the bar
|
||||
* @param array Options for the progress bar
|
||||
* @return bool
|
||||
*/
|
||||
function reset($formatstring, $bar, $prefill, $width, $target_num,
|
||||
$options = array())
|
||||
{
|
||||
if ($target_num == 0) {
|
||||
trigger_error("PEAR::Console_ProgressBar: Using a target number equal to 0 is invalid, setting to 1 instead");
|
||||
$this->_target_num = 1;
|
||||
} else {
|
||||
$this->_target_num = $target_num;
|
||||
}
|
||||
$default_options = array(
|
||||
'percent_precision' => 2,
|
||||
'fraction_precision' => 0,
|
||||
'percent_pad' => ' ',
|
||||
'fraction_pad' => ' ',
|
||||
'width_absolute' => true,
|
||||
'ansi_terminal' => false,
|
||||
'ansi_clear' => false,
|
||||
'num_datapoints' => 5,
|
||||
'min_draw_interval' => 0.0,
|
||||
);
|
||||
$intopts = array();
|
||||
foreach ($default_options as $key => $value) {
|
||||
if (!isset($options[$key])) {
|
||||
$intopts[$key] = $value;
|
||||
} else {
|
||||
settype($options[$key], gettype($value));
|
||||
$intopts[$key] = $options[$key];
|
||||
}
|
||||
}
|
||||
$this->_options = $options = $intopts;
|
||||
// placeholder
|
||||
$cur = '%2$\''.$options['fraction_pad'][0].strlen((int)$target_num).'.'
|
||||
.$options['fraction_precision'].'f';
|
||||
$max = $cur; $max[1] = 3;
|
||||
// pre php-4.3.7 %3.2f meant 3 characters before . and two after
|
||||
// php-4.3.7 and later it means 3 characters for the whole number
|
||||
if (version_compare(PHP_VERSION, '4.3.7', 'ge')) {
|
||||
$padding = 4 + $options['percent_precision'];
|
||||
} else {
|
||||
$padding = 3;
|
||||
}
|
||||
$perc = '%4$\''.$options['percent_pad'][0].$padding.'.'
|
||||
.$options['percent_precision'].'f';
|
||||
|
||||
$transitions = array(
|
||||
'%%' => '%%',
|
||||
'%fraction%' => $cur.'/'.$max,
|
||||
'%current%' => $cur,
|
||||
'%max%' => $max,
|
||||
'%percent%' => $perc.'%%',
|
||||
'%bar%' => '%1$s',
|
||||
'%elapsed%' => '%5$s',
|
||||
'%estimate%' => '%6$s',
|
||||
);
|
||||
|
||||
$this->_skeleton = strtr($formatstring, $transitions);
|
||||
|
||||
$slen = strlen(sprintf($this->_skeleton, '', 0, 0, 0, '00:00:00','00:00:00'));
|
||||
|
||||
if ($options['width_absolute']) {
|
||||
$blen = $width - $slen;
|
||||
$tlen = $width;
|
||||
} else {
|
||||
$tlen = $width + $slen;
|
||||
$blen = $width;
|
||||
}
|
||||
|
||||
$lbar = str_pad($bar, $blen, $bar[0], STR_PAD_LEFT);
|
||||
$rbar = str_pad($prefill, $blen, substr($prefill, -1, 1));
|
||||
|
||||
$this->_bar = substr($lbar,-$blen).substr($rbar,0,$blen);
|
||||
$this->_blen = $blen;
|
||||
$this->_tlen = $tlen;
|
||||
$this->_first = true;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ update($current)
|
||||
/**
|
||||
* Updates the bar with new progress information
|
||||
*
|
||||
* @param integer current position of the progress counter
|
||||
* @return bool
|
||||
*/
|
||||
function update($current)
|
||||
{
|
||||
$time = $this->_fetchTime();
|
||||
$this->_addDatapoint($current, $time);
|
||||
if ($this->_first) {
|
||||
if ($this->_options['ansi_terminal']) {
|
||||
echo "\x1b[s"; // save cursor position
|
||||
}
|
||||
$this->_first = false;
|
||||
$this->_start_time = $this->_fetchTime();
|
||||
$this->display($current);
|
||||
return;
|
||||
}
|
||||
if ($time - $this->_last_update_time <
|
||||
$this->_options['min_draw_interval'] and $current != $this->_target_num) {
|
||||
return;
|
||||
}
|
||||
$this->erase();
|
||||
$this->display($current);
|
||||
$this->_last_update_time = $time;
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ display($current)
|
||||
/**
|
||||
* Prints the bar. Usually, you don't need this method, just use update()
|
||||
* which handles erasing the previously printed bar also. If you use a
|
||||
* custom function (for whatever reason) to erase the bar, use this method.
|
||||
*
|
||||
* @param integer current position of the progress counter
|
||||
* @return bool
|
||||
*/
|
||||
function display($current)
|
||||
{
|
||||
$percent = $current / $this->_target_num;
|
||||
$filled = round($percent * $this->_blen);
|
||||
$visbar = substr($this->_bar, $this->_blen - $filled, $this->_blen);
|
||||
$elapsed = $this->_formatSeconds(
|
||||
$this->_fetchTime() - $this->_start_time
|
||||
);
|
||||
$estimate = $this->_formatSeconds($this->_generateEstimate());
|
||||
$this->_rlen = printf($this->_skeleton,
|
||||
$visbar, $current, $this->_target_num, $percent * 100, $elapsed,
|
||||
$estimate
|
||||
);
|
||||
// fix for php-versions where printf doesn't return anything
|
||||
if (is_null($this->_rlen)) {
|
||||
$this->_rlen = $this->_tlen;
|
||||
// fix for php versions between 4.3.7 and 5.x.y(?)
|
||||
} elseif ($this->_rlen < $this->_tlen) {
|
||||
echo str_repeat(' ', $this->_tlen - $this->_rlen);
|
||||
$this->_rlen = $this->_tlen;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ erase($clear = false)
|
||||
/**
|
||||
* Erases a previously printed bar.
|
||||
*
|
||||
* @param bool if the bar should be cleared in addition to resetting the
|
||||
* cursor position
|
||||
* @return bool
|
||||
*/
|
||||
function erase($clear = false)
|
||||
{
|
||||
if ($this->_options['ansi_terminal'] and !$clear) {
|
||||
if ($this->_options['ansi_clear']) {
|
||||
echo "\x1b[2K\x1b[u"; // restore cursor position
|
||||
} else {
|
||||
echo "\x1b[u"; // restore cursor position
|
||||
}
|
||||
} elseif (!$clear) {
|
||||
echo str_repeat(chr(0x08), $this->_rlen);
|
||||
} else {
|
||||
echo str_repeat(chr(0x08), $this->_rlen),
|
||||
str_repeat(chr(0x20), $this->_rlen),
|
||||
str_repeat(chr(0x08), $this->_rlen);
|
||||
}
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ format_seconds()
|
||||
/**
|
||||
* Returns a string containing the formatted number of seconds
|
||||
*
|
||||
* @param float The number of seconds
|
||||
* @return string
|
||||
*/
|
||||
function _formatSeconds($seconds)
|
||||
{
|
||||
$hou = floor($seconds/3600);
|
||||
$min = floor(($seconds - $hou * 3600) / 60);
|
||||
$sec = $seconds - $hou * 3600 - $min * 60;
|
||||
if ($hou == 0) {
|
||||
if (version_compare(PHP_VERSION, '4.3.7', 'ge')) {
|
||||
$format = '%2$02d:%3$05.2f';
|
||||
} else {
|
||||
$format = '%2$02d:%3$02.2f';
|
||||
}
|
||||
} elseif ($hou < 100) {
|
||||
$format = '%02d:%02d:%02d';
|
||||
} else {
|
||||
$format = '%05d:%02d';
|
||||
}
|
||||
return sprintf($format, $hou, $min, $sec);
|
||||
}
|
||||
// }}}
|
||||
|
||||
function _fetchTime() {
|
||||
if (!function_exists('microtime')) {
|
||||
return time();
|
||||
}
|
||||
if (version_compare(PHP_VERSION, '5.0.0', 'ge')) {
|
||||
return microtime(true);
|
||||
}
|
||||
return array_sum(explode(' ', microtime()));
|
||||
}
|
||||
|
||||
function _addDatapoint($val, $time) {
|
||||
if (count($this->_rate_datapoints)
|
||||
== $this->_options['num_datapoints']) {
|
||||
array_shift($this->_rate_datapoints);
|
||||
}
|
||||
$this->_rate_datapoints[] = array(
|
||||
'time' => $time,
|
||||
'value' => $val,
|
||||
);
|
||||
}
|
||||
|
||||
function _generateEstimate() {
|
||||
if (count($this->_rate_datapoints) < 2) {
|
||||
return 0.0;
|
||||
}
|
||||
$first = $this->_rate_datapoints[0];
|
||||
$last = end($this->_rate_datapoints);
|
||||
return ($this->_target_num - $last['value'])/($last['value'] - $first['value']) * ($last['time'] - $first['time']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* SOTESHOP/stInstallerPlugin
|
||||
*
|
||||
* Ten plik należy do aplikacji stInstallerPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
|
||||
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
|
||||
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
|
||||
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
|
||||
*
|
||||
* @package stInstallerPlugin
|
||||
* @subpackage libs
|
||||
* @copyright SOTE (www.sote.pl)
|
||||
* @license http://www.sote.pl/license/open (Open License SOTE) Otwarta Licencja SOTE
|
||||
* @version $Id: stInstallerOutputPake.class.php 3782 2010-03-05 13:39:42Z marek $
|
||||
* @author Marek Jakubowicz <marek.jakubowicz@sote.pl>
|
||||
*/
|
||||
|
||||
/**
|
||||
* PEAR Console ProgressBar
|
||||
*
|
||||
* @package stInstallerPlugin
|
||||
* @subpackage libs
|
||||
*/
|
||||
require_once (dirname(realpath(__FILE__)).DIRECTORY_SEPARATOR.'ProgressBar.class.php');
|
||||
|
||||
/**
|
||||
* Komunikaty dla konsoli (Pake)
|
||||
*
|
||||
* @package stInstallerPlugin
|
||||
* @subpackage libs
|
||||
*/
|
||||
class stInstallerOutputPake extends stInstallerOutput
|
||||
{
|
||||
public function message($message='')
|
||||
{
|
||||
pake_echo($message);
|
||||
}
|
||||
|
||||
public function progressBarStart($data=array())
|
||||
{
|
||||
$steps=$data['steps'];
|
||||
if (! empty($data['title'])) $title=$data['title'].' '; else $title='';
|
||||
$this->bar = new Console_ProgressBar($title.'[%bar%] %percent%', '=>', ' ', 80, $steps);
|
||||
|
||||
}
|
||||
|
||||
public function progressBarEnd()
|
||||
{
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
public function progressBarStep($data=array())
|
||||
{
|
||||
$i=$data['i'];
|
||||
$this->bar->update($i);
|
||||
}
|
||||
|
||||
public function listStart() {}
|
||||
|
||||
public function listAddItem($data=array()) {}
|
||||
|
||||
public function listEnd() {}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/**
|
||||
* SOTESHOP/stInstallerPlugin
|
||||
*
|
||||
* Ten plik należy do aplikacji stInstallerPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
|
||||
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
|
||||
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
|
||||
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
|
||||
*
|
||||
* @package stInstallerPlugin
|
||||
* @subpackage libs
|
||||
* @copyright SOTE (www.sote.pl)
|
||||
* @license http://www.sote.pl/license/open (Open License SOTE) Otwarta Licencja SOTE
|
||||
* @version $Id: stInstallerOutputWeb.php 3782 2010-03-05 13:39:42Z marek $
|
||||
* @author Marek Jakubowicz <marek.jakubowicz@sote.pl>
|
||||
*/
|
||||
|
||||
/**
|
||||
* PEAR Console ProgressBar
|
||||
*
|
||||
* @package stInstallerPlugin
|
||||
* @subpackage libs
|
||||
*/
|
||||
require_once (dirname(realpath(__FILE__)).DIRECTORY_SEPARATOR.'ProgressBar.class.php');
|
||||
|
||||
/**
|
||||
* Komunikaty dla strony WWW
|
||||
*
|
||||
* @package stInstallerPlugin
|
||||
* @subpackage libs
|
||||
*/
|
||||
class stInstallerOutputWeb extends stInstallerOutput
|
||||
{
|
||||
public function message($message='')
|
||||
{
|
||||
return print_r($message,true);
|
||||
}
|
||||
|
||||
public function progressBarStart($data=array())
|
||||
{
|
||||
return "start";
|
||||
}
|
||||
|
||||
public function progressBarEnd()
|
||||
{
|
||||
return "<br>koniec</br>\n";
|
||||
}
|
||||
|
||||
public function progressBarStep($data=array())
|
||||
{
|
||||
$i=$data['i'];
|
||||
return "i=$i<br>";
|
||||
// $this->bar->update($i);
|
||||
}
|
||||
|
||||
public function listStart() {}
|
||||
|
||||
public function listAddItem($data=array()) {}
|
||||
|
||||
public function listEnd() {}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/**
|
||||
* SOTESHOP/stInstallerPlugin
|
||||
*
|
||||
* Ten plik należy do aplikacji stInstallerPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
|
||||
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
|
||||
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
|
||||
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
|
||||
*
|
||||
* @package stInstallerPlugin
|
||||
* @subpackage libs
|
||||
* @copyright SOTE (www.sote.pl)
|
||||
* @license http://www.sote.pl/license/open (Open License SOTE) Otwarta Licencja SOTE
|
||||
* @version $Id: stInstallerOutputWebProgressBar.php 3782 2010-03-05 13:39:42Z marek $
|
||||
* @author Marek Jakubowicz <marek.jakubowicz@sote.pl>
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Komunikaty dla Web ProgressBar
|
||||
*
|
||||
* @package stInstallerPlugin
|
||||
* @subpackage libs
|
||||
*/
|
||||
class stInstallerOutputWebProgressBar extends stInstallerOutput
|
||||
{
|
||||
public function message($message='')
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function progressBarStart($data=array())
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function progressBarEnd()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function progressBarStep($data=array())
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function listStart() {}
|
||||
|
||||
public function listAddItem($data=array()) {}
|
||||
|
||||
public function listEnd() {}
|
||||
}
|
||||
91
plugins/stInstallerPlugin/lib/stAppStats.class.php
Normal file
91
plugins/stInstallerPlugin/lib/stAppStats.class.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
class stAppStats
|
||||
{
|
||||
const URL = 'https://www.sote.pl/app-stats';
|
||||
|
||||
protected static $version = null;
|
||||
|
||||
public static function activate($name, array $params = array())
|
||||
{
|
||||
$params['name'] = $name;
|
||||
return self::apiCall('/activate', $params);
|
||||
}
|
||||
|
||||
public static function deactivate($name, array $params = array())
|
||||
{
|
||||
$params['name'] = $name;
|
||||
return self::apiCall('/deactivate',$params);
|
||||
}
|
||||
|
||||
public static function apiCall($url , array $body = array())
|
||||
{
|
||||
if (!isset($body['hash']))
|
||||
{
|
||||
$body['hash'] = stConfig::getInstance('stRegister')->get('shop_hash');
|
||||
}
|
||||
|
||||
$body['version'] = self::getSoftwareVersion();
|
||||
|
||||
$ch = curl_init();
|
||||
|
||||
curl_setopt($ch, CURLOPT_URL, self::URL . $url);
|
||||
|
||||
curl_setopt($ch, CURLOPT_VERBOSE, true);
|
||||
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 2);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
|
||||
|
||||
// curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json' , 'Authorization: Bearer '. $apiKey));
|
||||
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
|
||||
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
|
||||
if (curl_errno($ch))
|
||||
{
|
||||
$result = array('error' => curl_error($ch));
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = array('http_code' => $httpcode, 'response' => $response, 'url' => self::URL . $url);
|
||||
}
|
||||
|
||||
|
||||
curl_close($ch);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function getSoftwareVersion()
|
||||
{
|
||||
if (null === self::$version)
|
||||
{
|
||||
$version = stRegisterSync::getPackageVersion('soteshop');
|
||||
|
||||
if (stCommunication::getIsSeven())
|
||||
{
|
||||
list(, $y, $z) = explode('.', $version, 3);
|
||||
$version = '7.'.($y-3).'.'.$z;
|
||||
}
|
||||
elseif (!$version)
|
||||
{
|
||||
$version = stRegisterSync::getPackageVersion('soteshop_base');
|
||||
}
|
||||
|
||||
self::$version = $version;
|
||||
}
|
||||
|
||||
return self::$version;
|
||||
}
|
||||
}
|
||||
259
plugins/stInstallerPlugin/lib/stFile.class.php
Normal file
259
plugins/stInstallerPlugin/lib/stFile.class.php
Normal file
@@ -0,0 +1,259 @@
|
||||
<?php
|
||||
/**
|
||||
* SOTESHOP/stInstallerPlugin
|
||||
*
|
||||
* Ten plik należy do aplikacji stInstallerPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
|
||||
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
|
||||
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
|
||||
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
|
||||
*
|
||||
* @package stInstallerPlugin
|
||||
* @subpackage libs
|
||||
* @copyright SOTE (www.sote.pl)
|
||||
* @license http://www.sote.pl/license/open (Open License SOTE) Otwarta Licencja SOTE
|
||||
* @version $Id: stFile.class.php 3782 2010-03-05 13:39:42Z marek $
|
||||
* @author Marek Jakubowicz <marek.jakubowicz@sote.pl>
|
||||
*/
|
||||
|
||||
/**
|
||||
* Komunikat błędu, dla trybu odczytywania listy plików z konfiguracji SVN.
|
||||
*/
|
||||
define("ERROR_SVN_NOTFOUND", "Check if the .svn exists in your package directories.");
|
||||
|
||||
/**
|
||||
* Pliki/Katalogi.
|
||||
* Operacje na plikach/katalogach.
|
||||
*
|
||||
* @package stInstallerPlugin
|
||||
* @subpackage libs
|
||||
*/
|
||||
class stFile
|
||||
{
|
||||
/**
|
||||
* Pliki, które są ignorowane przy kopiowaniu.
|
||||
* @var array
|
||||
*/
|
||||
private $ignore = array();
|
||||
|
||||
/**
|
||||
* Ustawia pliki ignorowane przy kopiowaniu.
|
||||
*
|
||||
* @param array $ignore
|
||||
*/
|
||||
public function setIgnore($ignore)
|
||||
{
|
||||
$this->ignore = $ignore;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rekurencyjne zakładanie katalogów
|
||||
*
|
||||
* @param string $dir zakładany katalog
|
||||
* @param string $rootDir ścieżka powyżej której nie będą zakładane katalogi
|
||||
* @return bool
|
||||
*/
|
||||
public function mkdir($dir, $rootDir = '')
|
||||
{
|
||||
if (empty($rootDIR)) $rootDir=sfConfig::get('sf_root_dir');
|
||||
if (! is_dir($dir))
|
||||
{
|
||||
if (@mkdir($dir))
|
||||
{
|
||||
return true;
|
||||
} else
|
||||
{
|
||||
$dir2 = dirname($dir);
|
||||
if ($dir2 == $rootDir)
|
||||
return false;
|
||||
else
|
||||
{
|
||||
$this->mkdir($dir2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@mkdir($dir);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rekurencyjne usuwanie katalogów.
|
||||
*
|
||||
* @see http://pl2.php.net/manual/pl/function.rmdir.php
|
||||
* @param string $folderPath usuwany katalog
|
||||
* @return bool
|
||||
*/
|
||||
function rmdir($folderPath)
|
||||
{
|
||||
if (is_dir($folderPath))
|
||||
{
|
||||
foreach (scandir($folderPath) as $value)
|
||||
{
|
||||
if ($value != "." && $value != "..")
|
||||
{
|
||||
$value = $folderPath . "/" . $value;
|
||||
if (is_dir($value))
|
||||
{
|
||||
$this->rmdir($value);
|
||||
} elseif (is_file($value))
|
||||
{
|
||||
@unlink($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rmdir($folderPath);
|
||||
} else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Usuń pliki lub katalogi
|
||||
*
|
||||
* @param string $path ścieżka usuwanego pliku lub katalogu
|
||||
* @return bool
|
||||
*/
|
||||
public function rm($path)
|
||||
{
|
||||
if (is_dir($path))
|
||||
{
|
||||
if ($this->rmdir($path)) return true;
|
||||
else return false;
|
||||
} elseif (unlink($path)) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Kopiowanie rekurencyjne katalogów.
|
||||
*
|
||||
* @see http://pear.php.net/manual/en/package.filesystem.file.php
|
||||
* @param string $source Katalog kopiowany.
|
||||
* @param string $target Katalog tworzony.
|
||||
* @throws ERROR_SVN_NOTFOUND
|
||||
*/
|
||||
public function copy($source, $target)
|
||||
{
|
||||
if (is_dir($source))
|
||||
{
|
||||
if (! $this->mkdir($target, sfConfig::get('sf_root_dir')))
|
||||
{
|
||||
throw new Exception(__CLASS__ . ': Cannot make directory: ' . $target . "\n");
|
||||
}
|
||||
|
||||
$d = dir($source);
|
||||
while (FALSE !== ($entry = $d->read()))
|
||||
{
|
||||
|
||||
if ($entry == '.' || $entry == '..')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (in_array($entry, $this->ignore))
|
||||
continue;
|
||||
|
||||
$Entry = $source . '/' . $entry;
|
||||
if (is_dir($Entry))
|
||||
{
|
||||
$this->copy($Entry, $target . '/' . $entry);
|
||||
continue;
|
||||
}
|
||||
if (! copy($Entry, $target . '/' . $entry))
|
||||
{
|
||||
throw new Exception(__CLASS__ . ': Cannot copy the file: ' . "\n" . $Entry . "\nto:\n" . $target . '/' . $entry . "\n\n[Sugestion]:\n" . ERROR_SVN_NOTFOUND);
|
||||
}
|
||||
}
|
||||
$d->close();
|
||||
|
||||
} else
|
||||
{
|
||||
if (! $this->mkdir(dirname($target), sfConfig::get('sf_root_dir')))
|
||||
{
|
||||
throw new Exception(__CLASS__ . ': Cannot make directory: ' . $target . "\n");
|
||||
}
|
||||
if (! (copy($source, $target)))
|
||||
{
|
||||
throw new Exception(__CLASS__ . ": Cannot copy the file:\n$source\nto:\n$target\n\n[Sugestion]:\n" . ERROR_SVN_NOTFOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwaraca listę plików ze wskazanego katalogu.
|
||||
*
|
||||
* @param string $dir
|
||||
* @param bool $hidden true - odczytaj ukryte pliki, false w p.w.
|
||||
* @return array
|
||||
*/
|
||||
static public function ls($dir, $hidden = false)
|
||||
{
|
||||
$d = dir($dir);
|
||||
$dr = array();
|
||||
if (is_object($d))
|
||||
{
|
||||
while (FALSE !== ($entry = $d->read()))
|
||||
{
|
||||
if ((preg_match("/^\\./", $entry)) && (! $hidden))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
array_push($dr, $entry);
|
||||
}
|
||||
$d->close();
|
||||
}
|
||||
return $dr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Odczytuje zawartość pliku.
|
||||
*
|
||||
* @param string $file
|
||||
* @return string Zawartość pliku.
|
||||
*/
|
||||
static public function read($file)
|
||||
{
|
||||
if ($fd = fopen($file, 'r'))
|
||||
{
|
||||
$data=fread($fd, filesize($file));
|
||||
fclose($fd);
|
||||
return $data;
|
||||
} else
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Zapisuje zawartość do pliku.
|
||||
*
|
||||
* @param string $file plik, do ktorego zpaisujemy dane
|
||||
* @param string $data dane
|
||||
* @return bool
|
||||
*/
|
||||
static public function write($file,$data)
|
||||
{
|
||||
if ($fd=fopen($file,"w+"))
|
||||
{
|
||||
fwrite($fd,$data,strlen($data));
|
||||
fclose($fd);
|
||||
return true;
|
||||
} else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Metoda do zweryfikowania działania unit-test dla klast StFile.
|
||||
*
|
||||
* @return 1
|
||||
*
|
||||
* @package stInstallerPlugin
|
||||
* @subpackage libs
|
||||
*/
|
||||
function classExistsTest()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
301
plugins/stInstallerPlugin/lib/stInstaller.class.php
Normal file
301
plugins/stInstallerPlugin/lib/stInstaller.class.php
Normal file
@@ -0,0 +1,301 @@
|
||||
<?php
|
||||
/**
|
||||
* SOTESHOP/stInstallerPlugin
|
||||
*
|
||||
* Ten plik należy do aplikacji stInstallerPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
|
||||
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
|
||||
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
|
||||
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
|
||||
*
|
||||
* @package stInstallerPlugin
|
||||
* @subpackage libs
|
||||
* @copyright SOTE (www.sote.pl)
|
||||
* @license http://www.sote.pl/license/open (Open License SOTE) Otwarta Licencja SOTE
|
||||
* @version $Id: stInstaller.class.php 3782 2010-03-05 13:39:42Z marek $
|
||||
* @author Marek Jakubowicz <marek.jakubowicz@sote.pl>
|
||||
*/
|
||||
|
||||
$error_reporting=ini_get('error_reporting');
|
||||
error_reporting(0 & ~E_STRICT);
|
||||
require_once 'PEAR'.DIRECTORY_SEPARATOR.'Config.php';
|
||||
require_once 'PEAR'.DIRECTORY_SEPARATOR.'Registry.php';
|
||||
error_reporting($error_reporting);
|
||||
|
||||
/**
|
||||
* Helper tablic PHP.
|
||||
*/
|
||||
require_once (sfConfig::get('sf_plugins_dir').DIRECTORY_SEPARATOR.'stInstallerPlugin'.DIRECTORY_SEPARATOR.'lib'.DIRECTORY_SEPARATOR.'helper'.DIRECTORY_SEPARATOR.'stArrayHelper.php');
|
||||
|
||||
/**
|
||||
* stInstallerIgnore class
|
||||
*/
|
||||
require_once (sfConfig::get('sf_plugins_dir').DIRECTORY_SEPARATOR.'stInstallerPlugin'.DIRECTORY_SEPARATOR.'lib'.DIRECTORY_SEPARATOR.'stInstallerIgnore.class.php');
|
||||
|
||||
/**
|
||||
*
|
||||
* @package stInstallerPlugin
|
||||
* @subpackage libs
|
||||
*/
|
||||
class stInstaller
|
||||
{
|
||||
/**
|
||||
* @var stInstallerFrontend abstract
|
||||
*/
|
||||
var $ui;
|
||||
|
||||
/**
|
||||
* Konstruktor
|
||||
*
|
||||
* @param string $mode (pake|web) określenie typu synchornizacji; pake - wykonywana z task'a, web - wykonywana przez www
|
||||
* @return true
|
||||
*/
|
||||
function __construct($mode='pake')
|
||||
{
|
||||
if ($mode=='pake')
|
||||
{
|
||||
// synchornizacja wykonywana z task'a
|
||||
$this->filemanager = stPakeFileManager::getInstance();
|
||||
} else {
|
||||
// synchronizacja wykonywana przez www
|
||||
$this->filemanager = stWebFileManager::getInstance();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Usatwia obiekt obsługujący wyświetlanie prezyjaznych dla użytkownika komunikatów, wartości.
|
||||
*
|
||||
* @param stInstallerOutput abstract class
|
||||
*/
|
||||
function setOutputObject(&$ui)
|
||||
{
|
||||
$this->ui=&$ui;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var array Lista zainstalowanych aplikacji przed instalacją.
|
||||
*/
|
||||
var $preData=array();
|
||||
|
||||
/**
|
||||
* @var array Lista zainstalowanych aplikacji przed instalacją.
|
||||
*/
|
||||
var $postData=array();
|
||||
|
||||
/**
|
||||
* Metoda wywoływana przed wykonaniem instalacji pakietów.
|
||||
*/
|
||||
public function preAction()
|
||||
{
|
||||
$this->preData=$this->getInstalledApps();
|
||||
}
|
||||
|
||||
/**
|
||||
* Metoda wywoływana po wykonaniu instalacji pakietów.
|
||||
*/
|
||||
public function postAction()
|
||||
{
|
||||
$this->postData=$this->getInstalledApps();
|
||||
$changes=$this->getChanges();
|
||||
// synchronizacja po instalacji pakietów
|
||||
// $this->sync($changes['all']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Synchronizje listę aplikacji z install/src do sf_root_dir
|
||||
*
|
||||
* @param array $apps
|
||||
* @param string $title
|
||||
* @return bool
|
||||
*/
|
||||
public function sync($apps,$title='')
|
||||
{
|
||||
|
||||
$regsync = new stRegisterSync();
|
||||
|
||||
$this->rootdir=sfConfig::get('sf_root_dir');
|
||||
// $this->cache=sfConfig::get('sf_root_cache_dir'); // old version for previous sync
|
||||
$this->cache=sfConfig::get('sf_root_dir').DIRECTORY_SEPARATOR.'install'.DIRECTORY_SEPARATOR.'sync';
|
||||
|
||||
if (empty($apps)) return true;
|
||||
|
||||
$data=array('steps'=>sizeof($apps),'title'=>$title);
|
||||
$this->ui->progressBarStart($data);
|
||||
#$this->filemanager->silentMode();
|
||||
$i=1;
|
||||
foreach ($apps as $app)
|
||||
{
|
||||
if ($this->_sync($app))
|
||||
{
|
||||
if (! $regsync->register($app)) return false;
|
||||
$data=array('i'=>$i++);
|
||||
|
||||
$this->filemanager->verboseMode();
|
||||
$this->ui->progressBarStep($data);
|
||||
# $this->filemanager->silentMode();
|
||||
|
||||
}
|
||||
}
|
||||
$this->filemanager->verboseMode();
|
||||
$this->ui->progressBarEnd();
|
||||
|
||||
unset($regsync); // memory optimization
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Synchronizuje aplikację. Synchronizacja install/src/stAppName -> soteshop
|
||||
*
|
||||
* @package string $app nazwa aplikacji
|
||||
*/
|
||||
protected function _sync($app)
|
||||
{
|
||||
// synchronizuje install/src/stAppName/stAppname -> soteshop
|
||||
$dir=sfConfig::get('sf_root_dir').DIRECTORY_SEPARATOR.'install'.DIRECTORY_SEPARATOR.'src';
|
||||
$from=$dir.DIRECTORY_SEPARATOR.$app.DIRECTORY_SEPARATOR.$app;
|
||||
|
||||
if (is_dir($from))
|
||||
{
|
||||
$this->filemanager->sync($from, $this->rootdir, $this->cache, true, '', $this->getIgnore($app));
|
||||
}
|
||||
|
||||
// synchronizuje install/src/stAppName
|
||||
$from=$dir.DIRECTORY_SEPARATOR.$app;
|
||||
|
||||
$delete=false;
|
||||
if (! is_dir($from))
|
||||
{
|
||||
$this->filemanager->mkdir($from);
|
||||
$delete=true;
|
||||
}
|
||||
|
||||
$disereg='install'.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.$app.DIRECTORY_SEPARATOR.$app;
|
||||
$this->filemanager->sync($from, $this->rootdir, $this->cache, true, $disereg, $this->getIgnore($app));
|
||||
if ($delete) $this->filemanager->remove($from);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Odczytuje i zwraca listę wyrażeń regularnych, dla pomijanych plików
|
||||
*
|
||||
* @param string $app nazwa aplikacji np. stAppName
|
||||
* @return array ignore|discard (discard - odrzuca zawsze, ignore - pomija jesli plik juz istnieje)
|
||||
*/
|
||||
private function getIgnore($app)
|
||||
{
|
||||
return stInstallerIgnore::getIgnore($app);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Odczytuje listę dodanych aplikacji.
|
||||
*
|
||||
* @see $this->setPreData() $this->setPostData()
|
||||
* @return array
|
||||
*/
|
||||
public function getChanges()
|
||||
{
|
||||
return st_array_diff($this->preData,$this->postData);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Uaktualnia konfigurację.
|
||||
* Dane odczytuje z __database.yml oraz __propel.ini i zapisuje w $sf_path_dir/config/propel.ini config/database.yml
|
||||
*
|
||||
* @param string $sf_path_dir Scieżka do głownego klatalogu instalacji. Jeśli jest pusta, pobierana jest wartosc SF_ROOT_DIR.
|
||||
* @param array $params array('database'=>array())
|
||||
* @return bool
|
||||
*/
|
||||
static function setConfig($params, $sf_path_dir='')
|
||||
{
|
||||
if (empty($sf_path_dir)) $sf_path_dir=sfConfig::get('sf_root_dir');
|
||||
if (empty($params['database'])) return false;
|
||||
|
||||
$schema = version_compare(phpversion(), '7.0.0', '<') ? 'mysql' : 'mysqli';
|
||||
|
||||
// setup database
|
||||
$databases_file = $sf_path_dir.DIRECTORY_SEPARATOR.sfConfig::get('sf_config_dir_name').DIRECTORY_SEPARATOR.'databases.yml';
|
||||
$data=sfYaml::load($databases_file);
|
||||
if (! empty($data['all']['propel']['param']))
|
||||
{
|
||||
foreach ($params['database'] as $key=>$val)
|
||||
{
|
||||
$data['all']['propel']['param'][$key]=$val;
|
||||
}
|
||||
}
|
||||
|
||||
$data['all']['propel']['param']['phptype'] = $schema;
|
||||
|
||||
if (! stFile::write($databases_file,sfYaml::dump($data))) return false;
|
||||
|
||||
// setup propel.ini
|
||||
$propelini_file = dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . sfConfig::get('sf_config_dir_name') . DIRECTORY_SEPARATOR . 'propel.ini';
|
||||
$data=stFile::read($propelini_file);
|
||||
$lines=explode("\n",$data);
|
||||
$lines2='';
|
||||
|
||||
foreach ($lines as $line)
|
||||
{
|
||||
$line2=$line;
|
||||
$dat=explode('=',$line,2);
|
||||
if (! empty($dat[1]))
|
||||
{
|
||||
$key1=$dat[0];$val1=$dat[1];
|
||||
$key=trim($key1); $db=$params['database'];
|
||||
switch ($key)
|
||||
{
|
||||
case "propel.database.createUrl":
|
||||
$line2=$key1.'= '.$schema.'://'.$db['username'].':'.$db['password'].'@'.$db['host'].'/'; // mysql://user:password@localhost/
|
||||
break;
|
||||
case "propel.database.url":
|
||||
$line2=$key1.'= '.$schema.'://'.$db['username'].':'.$db['password'].'@'.$db['host'].'/'.$db['database']; // mysql://user:password@localhost/database
|
||||
break;
|
||||
case "propel.output.dir":
|
||||
$line2=$key1.'= '.$sf_path_dir;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$lines2.=$line2."\n";
|
||||
}
|
||||
|
||||
if (! stFile::write($sf_path_dir.DIRECTORY_SEPARATOR.sfConfig::get('sf_config_dir_name').DIRECTORY_SEPARATOR.'propel.ini',$lines2)) throw new Exception ('The file '.$propelini_file.' wasn\'t updated.');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Odczytuje wersje i nazwy zainstalowanych aplikacji.
|
||||
*
|
||||
* @return array lista zainstalowanych aplikacji array("stAppName"=>"1.0.2",...)
|
||||
*/
|
||||
public function getInstalledApps() {
|
||||
|
||||
if (class_exists('stPear'))
|
||||
return stPear::getInstalledPackages();
|
||||
|
||||
$dat=array();
|
||||
$pear_user_file = sfConfig::get('sf_root_dir').DIRECTORY_SEPARATOR.'install'.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'.pearrc';
|
||||
$config = new PEAR_Config($pear_user_file, $pear_user_file);
|
||||
$registry = $config->getRegistry();
|
||||
$installed = $registry->packageInfo(null, null, null);
|
||||
|
||||
foreach ($installed as $channel=>$packages)
|
||||
{
|
||||
foreach ($packages as $package)
|
||||
{
|
||||
$pobj = $registry->getPackage(isset($package['package']) ? $package['package'] : $package['name'], $channel);
|
||||
$pkg=$pobj->getPackage();
|
||||
$ver=$pobj->getVersion();
|
||||
if ($pkg!='symfony') $dat[$pkg]=$ver;
|
||||
}
|
||||
}
|
||||
|
||||
return $dat;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
61
plugins/stInstallerPlugin/lib/stInstallerHistory.class.php
Normal file
61
plugins/stInstallerPlugin/lib/stInstallerHistory.class.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/**
|
||||
* SOTESHOP/stUpdate
|
||||
*
|
||||
* Ten plik należy do aplikacji stUpdate opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
|
||||
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
|
||||
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
|
||||
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
|
||||
*
|
||||
* @package stUpdate
|
||||
* @subpackage libs
|
||||
* @copyright SOTE (www.sote.pl)
|
||||
* @license http://www.sote.pl/license/open (Open License SOTE) Otwarta Licencja SOTE
|
||||
* @version $Id: stInstallerHistory.class.php 3782 2010-03-05 13:39:42Z marek $
|
||||
* @author Marek Jakubowicz <marek.jakubowicz@sote.pl>
|
||||
*/
|
||||
|
||||
/**
|
||||
* Baza z historią aktualizacji.
|
||||
*/
|
||||
define ("ST_HISTORY_INSTALLER_DB",sfConfig::get('sf_root_dir').DIRECTORY_SEPARATOR.'install'.DIRECTORY_SEPARATOR.'db'.DIRECTORY_SEPARATOR.'.history.reg');
|
||||
|
||||
/**
|
||||
* Historia aktualizacji.
|
||||
*/
|
||||
class stInstallerHistory
|
||||
{
|
||||
private $history = array();
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
if (file_exists(ST_HISTORY_INSTALLER_DB))
|
||||
{
|
||||
$data = file_get_contents(ST_HISTORY_INSTALLER_DB);
|
||||
$this->history = unserialize($data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwraca historię aktualizacji
|
||||
* @param int $limit liczba ostatnich aktualizacji, 0 - zwraca wszystkie aktualizacje
|
||||
* @return array
|
||||
*/
|
||||
public function getHistory($limit=0)
|
||||
{
|
||||
return $this->history;
|
||||
}
|
||||
|
||||
public function add($package,$version)
|
||||
{
|
||||
$this->history[date('Y/m/d')][]=array('package'=>$package,'version'=>$version,'date'=>date('Y:m:d H:i:s'));
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$data = serialize($this->history);
|
||||
file_put_contents(ST_HISTORY_INSTALLER_DB,$data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
85
plugins/stInstallerPlugin/lib/stInstallerIgnore.class.php
Normal file
85
plugins/stInstallerPlugin/lib/stInstallerIgnore.class.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
/**
|
||||
* SOTESHOP/stInstallerPlugin
|
||||
*
|
||||
* Ten plik należy do aplikacji stInstallerPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
|
||||
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
|
||||
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
|
||||
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
|
||||
*
|
||||
* @package stInstallerPlugin
|
||||
* @subpackage lib
|
||||
* @copyright SOTE (www.sote.pl)
|
||||
* @license http://www.sote.pl/license/open (Open License SOTE) Otwarta Licencja SOTE
|
||||
* @version $Id: stInstallerIgnore.class.php 3782 2010-03-05 13:39:42Z marek $
|
||||
* @author Marek Jakubowicz <marek.jakubowicz@sote.pl>
|
||||
*/
|
||||
|
||||
/**
|
||||
* Baza ignorowanych plików synchornizacji
|
||||
*/
|
||||
class stInstallerIgnore
|
||||
{
|
||||
/**
|
||||
* Odczytuje i zwraca listę wyrażeń regularnych, dla pomijanych plików
|
||||
*
|
||||
* @param string $app nazwa aplikacji np. stAppName
|
||||
* @return array(ereg=>(ignore|discard)) discard - odrzuca zawsze, ignore - pomija jesli plik juz istnieje
|
||||
*/
|
||||
static public function getIgnore($app)
|
||||
{
|
||||
|
||||
$ignore=array();
|
||||
|
||||
$file=sfConfig::get('sf_root_dir').DIRECTORY_SEPARATOR.'packages'.DIRECTORY_SEPARATOR.$app.DIRECTORY_SEPARATOR.'ignore.yml';
|
||||
if (file_exists($file))
|
||||
{
|
||||
$data=sfYaml::load($file);
|
||||
if (! empty($data['ignore']))
|
||||
{
|
||||
$ignore = $data['ignore'];
|
||||
}
|
||||
}
|
||||
|
||||
$file=sfConfig::get('sf_root_dir').DIRECTORY_SEPARATOR.'install'.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.
|
||||
$app.DIRECTORY_SEPARATOR.'packages'.DIRECTORY_SEPARATOR.$app.DIRECTORY_SEPARATOR.'ignore.yml';
|
||||
if (file_exists($file))
|
||||
{
|
||||
$data=sfYaml::load($file);
|
||||
if (! empty($data['ignore']))
|
||||
{
|
||||
$ignore = array_merge($ignore, $data['ignore']);
|
||||
}
|
||||
}
|
||||
|
||||
return $ignore;
|
||||
}
|
||||
|
||||
/**
|
||||
* Odczytywanie listy wzorców dla plików, które mają zostać zsynchronizowane.
|
||||
* W przypadku ignore_replace pliki te będą trakowane jako ignore jeżeli zostąły zmienione, w przeciwnym wypadku będą napisywane.
|
||||
*
|
||||
* @param string $app Nazwa aplikacji
|
||||
* @return array lista wzorców dla plików
|
||||
*/
|
||||
static public function getIgnoreReplace($app)
|
||||
{
|
||||
$files = array(sfConfig::get('sf_root_dir').DIRECTORY_SEPARATOR.'packages'.DIRECTORY_SEPARATOR.$app.DIRECTORY_SEPARATOR.'ignore.yml',
|
||||
sfConfig::get('sf_root_dir').DIRECTORY_SEPARATOR.'install'.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.$app.DIRECTORY_SEPARATOR.'packages'.DIRECTORY_SEPARATOR.$app.DIRECTORY_SEPARATOR.'ignore.yml');
|
||||
|
||||
$ignoreReplace = array();
|
||||
|
||||
foreach($files as $file)
|
||||
{
|
||||
if (file_exists($file))
|
||||
{
|
||||
$data = sfYaml::load($file);
|
||||
if (isset($data['ignore_replace'])) $ignoreReplace = array_merge($ignoreReplace, $data['ignore_replace']);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return array_unique($ignoreReplace);
|
||||
}
|
||||
}
|
||||
|
||||
71
plugins/stInstallerPlugin/lib/stInstallerOutput.class.php
Normal file
71
plugins/stInstallerPlugin/lib/stInstallerOutput.class.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/**
|
||||
* SOTESHOP/stInstallerPlugin
|
||||
*
|
||||
* Ten plik należy do aplikacji stInstallerPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
|
||||
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
|
||||
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
|
||||
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
|
||||
*
|
||||
* @package stInstallerPlugin
|
||||
* @subpackage libs
|
||||
* @copyright SOTE (www.sote.pl)
|
||||
* @license http://www.sote.pl/license/open (Open License SOTE) Otwarta Licencja SOTE
|
||||
* @version $Id: stInstallerOutput.class.php 3782 2010-03-05 13:39:42Z marek $
|
||||
* @author Marek Jakubowicz <marek.jakubowicz@sote.pl>
|
||||
*/
|
||||
|
||||
/**
|
||||
* Klasa abstrakcyjna definicująca wyświetlanie komuniakatów dla obiektów klasy stInstaller
|
||||
*
|
||||
* @package stInstallerPlugin
|
||||
* @subpackage libs
|
||||
*/
|
||||
abstract class stInstallerOutput
|
||||
{
|
||||
/**
|
||||
* Wyświetla komunikat.
|
||||
*
|
||||
* @param string $message
|
||||
*/
|
||||
abstract public function message($message='');
|
||||
|
||||
/**
|
||||
* Otwiera progressbar
|
||||
*
|
||||
* @param data $array
|
||||
*/
|
||||
abstract public function progressBarStart($data=array());
|
||||
|
||||
/**
|
||||
* Zamyka progressbar
|
||||
*/
|
||||
abstract public function progressBarEnd();
|
||||
|
||||
/**
|
||||
* Wywołuje kolejny krok w pasku postępu (progressbar)
|
||||
*
|
||||
* @param array $data dane potrzebne do wyświetlenia paska postępu
|
||||
*/
|
||||
abstract public function progressBarStep($data=array());
|
||||
|
||||
/**
|
||||
* Otwiera listę wyników
|
||||
*/
|
||||
abstract public function listStart();
|
||||
|
||||
/**
|
||||
* Dodaje element do listy
|
||||
*
|
||||
* @param array $data dane potrzebne do wyświetlenia elementu listy
|
||||
*/
|
||||
abstract public function listAddItem($data=array());
|
||||
|
||||
/**
|
||||
* Żamyka listę wyników
|
||||
*/
|
||||
abstract public function listEnd();
|
||||
|
||||
}
|
||||
|
||||
|
||||
145
plugins/stInstallerPlugin/lib/stLicenseInfo.class.php
Normal file
145
plugins/stInstallerPlugin/lib/stLicenseInfo.class.php
Normal file
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
/**
|
||||
* SOTESHOP/stInstallerPlugin
|
||||
*
|
||||
* Ten plik należy do aplikacji stInstallerPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
|
||||
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
|
||||
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
|
||||
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
|
||||
*
|
||||
* @package stInstallerPlugin
|
||||
* @subpackage libs
|
||||
* @copyright SOTE (www.sote.pl)
|
||||
* @license http://www.sote.pl/license/open (Open License SOTE) Otwarta Licencja SOTE
|
||||
* @version $Id: stLicenseInfo.class.php 3782 2010-03-05 13:39:42Z marek $
|
||||
* @author Marek Jakubowicz <marek.jakubowicz@sote.pl>
|
||||
*/
|
||||
|
||||
/**
|
||||
* Komunikat dla skryptów serwera, że demo jest do usunięcia. Nie można go zmieniać!
|
||||
*/
|
||||
define("ST_LICENSE_EXPIRED",'[EXPIRED]');
|
||||
|
||||
/**
|
||||
* Komunikat, że demo jest niaktywne ale nie do usunięcia.
|
||||
*/
|
||||
define ("ST_LICENSE_DISABLED",'[DISABLED]');
|
||||
|
||||
/**
|
||||
* Komunikat, że demo jest aktywne
|
||||
*/
|
||||
define ("ST_LICENSE_ACTIVE",'[ACTIVE]');
|
||||
|
||||
/**
|
||||
* Komunikat o błędnej licencji
|
||||
*/
|
||||
define ("ST_LICENSE_INVALID",'[INVALID]');
|
||||
|
||||
/**
|
||||
* Ilość dni od wygaśnięcia licencji, po których zmienia status na EXPIRED (do usunięcia).
|
||||
*/
|
||||
define ("ST_LICENSE_EXPIRE_LIMIT",7);
|
||||
|
||||
/**
|
||||
* stLicensenIstaller class
|
||||
*/
|
||||
require_once ('install'.DIRECTORY_SEPARATOR.'installer'.DIRECTORY_SEPARATOR.'cli'.DIRECTORY_SEPARATOR.'lib'.DIRECTORY_SEPARATOR.'stLicenseInstaller.php');
|
||||
|
||||
/**
|
||||
* Weryfikacja licencji.
|
||||
* @package stInstallerPlugin
|
||||
*/
|
||||
class stLicenseInfo extends stLicenseInstaller {
|
||||
|
||||
/**
|
||||
* Klucz licencji
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $licenseKey = '071174180986080181986863209823MK';
|
||||
|
||||
public function checkLicenseSign($license)
|
||||
{
|
||||
$license = $this->clearLicense($license);
|
||||
$licenseLenght = strlen($license);
|
||||
|
||||
if ($licenseLenght != 24) return false;
|
||||
|
||||
$licenseNoSign = substr($license, 0, $licenseLenght-8);
|
||||
$licenseSign = substr($license, $licenseLenght-8, 8);
|
||||
|
||||
$code = md5($this->licenseKey.$licenseNoSign);
|
||||
$codeSign = substr($code, strlen($code)-8, 8);
|
||||
|
||||
if ($codeSign == $licenseSign) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
protected function clearLicense($license)
|
||||
{
|
||||
return str_replace(array(" ", "-"), "", $license);
|
||||
}
|
||||
|
||||
protected function getLicenseCreateDate($license)
|
||||
{
|
||||
$license = $this->clearLicense($license);
|
||||
|
||||
$year = substr($license, 0, 4);
|
||||
$month = substr($license, 4, 2);
|
||||
$day = substr($license, 6, 2);
|
||||
|
||||
return mktime(0, 0, 0, $month, $day, $year);
|
||||
}
|
||||
|
||||
protected function getLicenseDayLimit($license)
|
||||
{
|
||||
$license = $this->clearLicense($license);
|
||||
return substr($license, 8, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sprawdzanie czy można usunąć demo.
|
||||
*
|
||||
* @param string $license
|
||||
* @param int $limit ilość dni po przeterminowaniu licencji, po których sklep jest usuwany automatycznie
|
||||
* @return string ST_LICENSE_EXPIRED ST_LICENSE_DISABLED ST_LICENSE_ACTIVE
|
||||
*/
|
||||
public function getLicenseStatus($license,$limit=ST_LICENSE_EXPIRE_LIMIT)
|
||||
{
|
||||
if (! $this->checkLicenseSign($license))
|
||||
{
|
||||
pake_echo ("License status: ".ST_LICENSE_INVALID);
|
||||
return ST_LICENSE_INVALID;
|
||||
}
|
||||
|
||||
$license = $this->clearLicense($license);
|
||||
|
||||
$licenseCreateDate = $this->getLicenseCreateDate($license);
|
||||
$licenseDayLimit = $this->getLicenseDayLimit($license);
|
||||
|
||||
if ($licenseDayLimit == 0)
|
||||
{
|
||||
pake_echo ("License status: ".ST_LICENSE_ACTIVE);
|
||||
return ST_LICENSE_ACTIVE;
|
||||
}
|
||||
|
||||
$currentDate = mktime(0, 0, 0, date('n'), date('j'), date('Y'));
|
||||
$licenseLimitDateExp = $licenseCreateDate + (($licenseDayLimit+$limit)*24*60*60);
|
||||
$licenseLimitDate = $licenseCreateDate + (($licenseDayLimit)*24*60*60);
|
||||
|
||||
if($currentDate > $licenseLimitDateExp) {
|
||||
pake_echo ("License status: ".ST_LICENSE_EXPIRED);
|
||||
return ST_LICENSE_EXPIRED;
|
||||
} elseif($currentDate > $licenseLimitDate)
|
||||
{
|
||||
pake_echo ("License status: ".ST_LICENSE_DISABLED);
|
||||
return ST_LICENSE_DISABLED;
|
||||
} else
|
||||
{
|
||||
|
||||
pake_echo ("License status: ".ST_LICENSE_ACTIVE);
|
||||
return ST_LICENSE_ACTIVE;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
255
plugins/stInstallerPlugin/lib/stNewServer.class.php
Normal file
255
plugins/stInstallerPlugin/lib/stNewServer.class.php
Normal file
@@ -0,0 +1,255 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Marek Jakubowicz <marek.jakubowicz@sote.pl>
|
||||
*/
|
||||
|
||||
/**
|
||||
* Setup software for new server
|
||||
*/
|
||||
class stNewServer
|
||||
{
|
||||
/**
|
||||
* @var stPearInfo
|
||||
*/
|
||||
var $peari;
|
||||
|
||||
/**
|
||||
* @var string Old path
|
||||
*/
|
||||
var $oldpath;
|
||||
|
||||
/**
|
||||
* @var string New path
|
||||
*/
|
||||
var $newpath;
|
||||
|
||||
/**
|
||||
* @var string Old DIRECTORY_SEPARATOR
|
||||
*/
|
||||
var $oldds;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->peari = stPearInfo::getInstance();
|
||||
|
||||
$oldpath = $this->getOldPath();
|
||||
$newpath = sfConfig::get('sf_root_dir');
|
||||
|
||||
// delete last DIRECTORY_SEPARATOR Unix or Windows (system doesn't know which)
|
||||
$oldpath=preg_replace("/\/$/",'',$oldpath);
|
||||
$oldpath=preg_replace("/"."\\\\"."$/",'',$oldpath);
|
||||
$newpath=preg_replace("/\/$/",'',$newpath);
|
||||
$newpath=preg_replace("/"."\\\\"."$/",'',$newpath);
|
||||
|
||||
$this->oldpath=$oldpath;
|
||||
$this->newpath=$newpath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detecting new server
|
||||
* @return bool true - new server, false - the same
|
||||
*/
|
||||
public function newServer()
|
||||
{
|
||||
if ($this->oldpath!=$this->newpath) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update
|
||||
* @return bool
|
||||
*/
|
||||
public function update()
|
||||
{
|
||||
// this update should be executed 2x
|
||||
if (!(($this->peari->updateConfig()))) return false;
|
||||
if (! $this->updateMd5()) return false;
|
||||
if (! $this->updateRegistry()) return false;
|
||||
if (! $this->updateSync()) return false;
|
||||
if (! $this->cleanSmartyCache()) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear smarty cache files from cache/smarty_c
|
||||
* @return bool
|
||||
*/
|
||||
public function cleanSmartyCache()
|
||||
{
|
||||
$files=sfFinder::type('file')->name("*.html.php")->in(sfConfig::get('sf_root_dir').DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR.'smarty_c');
|
||||
foreach ($files as $cache_file)
|
||||
{
|
||||
if (! unlink($cache_file)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get old path for prevoius localization.
|
||||
* @return string
|
||||
*/
|
||||
protected function getOldPath()
|
||||
{
|
||||
$pearrc=$this->peari->getPearrc();
|
||||
$php_dir=$pearrc['php_dir']; // [php_dir] => /Users/marek/Web/soteshop.502//install/src
|
||||
if (preg_match('/\\\\/',$php_dir))
|
||||
{
|
||||
$this->oldds='\\'; // DIRECTORY_SEPARATOR Windows
|
||||
} else {
|
||||
$this->oldds='/'; // DIRECTORY_SEPARATOR Unix
|
||||
}
|
||||
$data=preg_split('/install\\'.$this->oldds.'src/',$php_dir);
|
||||
if (isset($data[1]))
|
||||
{
|
||||
$oldpath=$data[0];
|
||||
if (preg_match('/\\'.$this->oldds.'$/',$oldpath)) $oldpath=substr($oldpath,0,strlen($oldpath)-1);
|
||||
return $oldpath;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fix path. Update path for new localization.
|
||||
*
|
||||
* @param string $path previous path
|
||||
* @return string new path
|
||||
*/
|
||||
protected function fixpath($path)
|
||||
{
|
||||
$path=str_replace($this->oldpath,$this->newpath, $path); // change SF_ROOT_DIR
|
||||
$path=str_replace($this->oldds, DIRECTORY_SEPARATOR, $path); // change DIRECTORY_SEPARATOR
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update registry
|
||||
* @return bool
|
||||
*/
|
||||
protected function _updateRegistry($dir)
|
||||
{
|
||||
$files=sfFinder::type('file')->name('*.reg')->in($dir);
|
||||
foreach ($files as $file)
|
||||
{
|
||||
$raw=file_get_contents($file);
|
||||
$data=unserialize($raw);
|
||||
if (is_array($data))
|
||||
{
|
||||
// filelist: Array
|
||||
// (
|
||||
// [soteshop/packages/soteshop/package.yml] => Array
|
||||
// (
|
||||
// [baseinstalldir] => /
|
||||
// [md5sum] => 6719d9728de9a3fa5a761900c0e638b6
|
||||
// [name] => soteshop/packages/soteshop/package.yml
|
||||
// [role] => php
|
||||
// [installed_as] => /Users/marek/Web/soteshop.test/install/src/soteshop/packages/soteshop/package.yml
|
||||
// )
|
||||
//
|
||||
// )
|
||||
$filelist=$data['filelist'];
|
||||
foreach ($filelist as $key=>$file_data)
|
||||
{
|
||||
$data['filelist'][$key]['installed_as']=$this->fixpath($data['filelist'][$key]['installed_as']);
|
||||
}
|
||||
|
||||
// dirtree: Array
|
||||
// (
|
||||
// [/Users/marek/Web/soteshop.test/install/src/soteshop/packages/soteshop] => 1
|
||||
// [/Users/marek/Web/soteshop.test/install/src/soteshop/packages] => 1
|
||||
// [/Users/marek/Web/soteshop.test/install/src/soteshop] => 1
|
||||
// )
|
||||
$dirtree=$data['dirtree'];$dirtree_updated=array();
|
||||
foreach ($dirtree as $dir=>$set)
|
||||
{
|
||||
$dirtree_updated[$this->fixpath($dir)]=$set;
|
||||
}
|
||||
$data['dirtree']=$dirtree_updated;
|
||||
|
||||
file_put_contents($file,serialize($data));
|
||||
} else return false;
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update install/src/.registry/.channel.pear.sote.pl
|
||||
*/
|
||||
protected function updateRegistry()
|
||||
{
|
||||
$dir=$this->newpath.DIRECTORY_SEPARATOR.'install'.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'.registry'.DIRECTORY_SEPARATOR;
|
||||
$channels_dirs=sfFinder::type('dir')->relative()->in($dir);
|
||||
foreach ($channels_dirs as $id=>$channel_dir)
|
||||
{
|
||||
if (! $this->_updateRegistry($dir.DIRECTORY_SEPARATOR.$channel_dir)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update install/db/.md5
|
||||
*/
|
||||
protected function updateMd5()
|
||||
{
|
||||
$dir=$this->newpath.DIRECTORY_SEPARATOR.'install'.DIRECTORY_SEPARATOR.'db'.DIRECTORY_SEPARATOR.'.md5sum';
|
||||
return $this->_updateRegistry($dir);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update cache/*.sync
|
||||
* Update files in old localisation cache/*.sync and new install/sync/*.sync
|
||||
*/
|
||||
protected function updateSync()
|
||||
{
|
||||
$files_sync_old = sfFinder::type('file')->name('*.sync')->in($this->newpath.DIRECTORY_SEPARATOR.'cache'); // old cache
|
||||
$files_sync_new = sfFinder::type('file')->name('*.sync')->in($this->newpath.DIRECTORY_SEPARATOR.'install'.DIRECTORY_SEPARATOR.'sync'); // new cache
|
||||
$files_sync = array_merge($files_sync_old,$files_sync_new);
|
||||
foreach ($files_sync as $file_pkg)
|
||||
{
|
||||
// Source:
|
||||
// /Users/marek/Web/soteshop.test/apps
|
||||
// /Users/marek/Web/soteshop.test/apps/backend
|
||||
// /Users/marek/Web/soteshop.test/apps/backend/i18n
|
||||
// /Users/marek/Web/soteshop.test/apps/backend/i18n/stAllegroBackend.pl.xml
|
||||
// ...
|
||||
$source=file_get_contents($file_pkg);
|
||||
|
||||
$lines=explode("\n", $source);$new_source='';
|
||||
foreach ($lines as $line)
|
||||
{
|
||||
$new_source.=$this->fixpath($line)."\n";
|
||||
}
|
||||
$file_pkg_new = $this->renameSyncFile($file_pkg);
|
||||
if ($file_pkg_new != $file_pkg)
|
||||
{
|
||||
if (file_put_contents($file_pkg_new,$new_source))
|
||||
{
|
||||
// delete old file name
|
||||
unlink($file_pkg);
|
||||
} else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename sync files. Update path.
|
||||
* @param string $file eg. %2FUsers%2Fmarek%2FWeb%2Fsoteshop.test%2Finstall%2Fsrc%2FstUser.sync
|
||||
* @return string the same as $file but with new path
|
||||
*/
|
||||
public function renameSyncFile($file)
|
||||
{
|
||||
$file_name = basename($file);
|
||||
$file_name = str_replace('%2F',$this->oldds,$file_name);
|
||||
$file_name = $this->fixpath($file_name);
|
||||
$file_name = str_replace(DIRECTORY_SEPARATOR,'%2F',$file_name);
|
||||
$file=dirname($file).DIRECTORY_SEPARATOR.$file_name;
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
88
plugins/stInstallerPlugin/lib/stPearDownload.class.php
Normal file
88
plugins/stInstallerPlugin/lib/stPearDownload.class.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
/**
|
||||
* SOTESHOP/stInstallerPlugin
|
||||
*
|
||||
* Ten plik należy do aplikacji stInstallerPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
|
||||
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
|
||||
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
|
||||
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
|
||||
*
|
||||
* @package stInstallerPlugin
|
||||
* @subpackage libs
|
||||
* @copyright SOTE (www.sote.pl)
|
||||
* @license http://www.sote.pl/license/open (Open License SOTE) Otwarta Licencja SOTE
|
||||
* @version $Id: stPearDownload.class.php 3782 2010-03-05 13:39:42Z marek $
|
||||
* @author Marek Jakubowicz <marek.jakubowicz@sote.pl>
|
||||
*/
|
||||
|
||||
/**
|
||||
* Pliki i katalogi z PEAR->Downloads install/download
|
||||
* @package stInstallerPlugin
|
||||
*/
|
||||
class stPearDownload
|
||||
{
|
||||
/**
|
||||
* @var $int ilość usuniętych plików
|
||||
*/
|
||||
private $count=0;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
var $download_dir;
|
||||
|
||||
/**
|
||||
* Konstruktor.
|
||||
*/
|
||||
public function __construct($download_dir='download')
|
||||
{
|
||||
$this->download_dir=sfConfig::get('sf_root_dir').DIRECTORY_SEPARATOR.'install'.DIRECTORY_SEPARATOR.$download_dir;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwraca listę pakietów.
|
||||
* @return array
|
||||
*/
|
||||
public function getPackages()
|
||||
{
|
||||
$result=sfFinder::type('dir')->name("st*")->maxdepth(0)->relative()->in($this->download_dir);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Usuwa wskazany pakiet.
|
||||
*
|
||||
* @param string $package
|
||||
* @return bool
|
||||
*/
|
||||
public function deletePackage($package)
|
||||
{
|
||||
$package_dir = $this->download_dir.DIRECTORY_SEPARATOR.$package;
|
||||
$package_file = $this->download_dir.DIRECTORY_SEPARATOR.$package.'.tgz';
|
||||
|
||||
if (! is_dir($package_dir)) return true;
|
||||
|
||||
$files=sfFinder::type('any')->in($package_dir);
|
||||
$items=array_reverse($files);
|
||||
foreach ($items as $item)
|
||||
{
|
||||
if (is_file($item)) { unlink($item); $this->count++; }
|
||||
elseif (is_dir($item)) { rmdir($item); $this->count++; }
|
||||
else return false;
|
||||
}
|
||||
|
||||
if (is_dir($package_dir)) rmdir($package_dir);
|
||||
if (is_file($package_file)) unlink($package_file);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwraca liczbę usuniętych plików i katalogów.
|
||||
*/
|
||||
public function getCountDeleted()
|
||||
{
|
||||
return $this->count;
|
||||
}
|
||||
}
|
||||
515
plugins/stInstallerPlugin/lib/stPearInfo.class.php
Normal file
515
plugins/stInstallerPlugin/lib/stPearInfo.class.php
Normal file
@@ -0,0 +1,515 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* SOTESHOP/stInstallerPlugin
|
||||
*
|
||||
* Ten plik należy do aplikacji stInstallerPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
|
||||
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
|
||||
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
|
||||
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
|
||||
*
|
||||
* @package stInstallerPlugin
|
||||
* @subpackage libs
|
||||
* @copyright SOTE (www.sote.pl)
|
||||
* @license http://www.sote.pl/license/open (Open License SOTE) Otwarta Licencja SOTE
|
||||
* @version $Id: stPearInfo.class.php 4329 2010-03-30 13:17:13Z marek $
|
||||
* @author Marek Jakubowicz <marek.jakubowicz@sote.pl>
|
||||
*/
|
||||
|
||||
/**
|
||||
* Katalog z bazą danych sum kontrolnych
|
||||
*/
|
||||
if (!defined('ST_APP_REGISTRY_MD5SUM'))
|
||||
define("ST_APP_REGISTRY_MD5SUM", sfConfig::get('sf_root_dir') . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR . 'db' . DIRECTORY_SEPARATOR . '.md5sum');
|
||||
|
||||
/**
|
||||
* Plik optymalizacji danych PEAR summary
|
||||
*/
|
||||
define("ST_PEAR_OPT_SUMMARY", sfConfig::get('sf_root_dir') . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR . 'db' . DIRECTORY_SEPARATOR . '.pearsummary');
|
||||
|
||||
/**
|
||||
* Plik optymalizacji danych PEAR versions
|
||||
*/
|
||||
define("ST_PEAR_OPT_VERSIONS", sfConfig::get('sf_root_dir') . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR . 'db' . DIRECTORY_SEPARATOR . '.pearversions');
|
||||
|
||||
|
||||
/**
|
||||
* Zwaraca informacje o pakietach PEAR zainstaowanych z lokalnym repozytorium.
|
||||
*
|
||||
* @package stInstallerPlugin
|
||||
* @subpackage libs
|
||||
*/
|
||||
class stPearInfo
|
||||
{
|
||||
|
||||
/**
|
||||
* @var string ścieżka do konfiguracji PEAR
|
||||
*/
|
||||
protected $pearCfg;
|
||||
|
||||
/**
|
||||
* @var string katalog zawierający instlację PEAR
|
||||
*/
|
||||
protected $pearDir;
|
||||
|
||||
/**
|
||||
* Instancja klasy. Singleton.
|
||||
* @var self
|
||||
*/
|
||||
protected static $instance = array();
|
||||
|
||||
/**
|
||||
* @var string rodzaj weryfikacji danych o pakietach
|
||||
* install - weryfikuje dane z bazy .registry, verify - weryfikuje dane z .registry i .md5sum
|
||||
*/
|
||||
protected $mode = 'install';
|
||||
|
||||
/**
|
||||
* 1 linia pliku .pearrc
|
||||
*/
|
||||
protected $pearrcVersionHead = "#PEAR_Config 0.9";
|
||||
|
||||
/**
|
||||
* Lista wersji pakietów
|
||||
*
|
||||
* @var array array('packageName'=>'version',...)
|
||||
*/
|
||||
protected $versions = null;
|
||||
|
||||
/**
|
||||
* Lista nazwa pakietów
|
||||
*
|
||||
* @var array array('packageName'=>'name',...)
|
||||
*/
|
||||
protected $packages = null;
|
||||
|
||||
/**
|
||||
* Lista pakietów wraz z pełnymi danymi z repozytorium pear
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $pearPackages = null;
|
||||
|
||||
/**
|
||||
* Singleton (2x)
|
||||
* At the same time can be set more than one instance.
|
||||
* Default system use 2 instances in install & verify mode.
|
||||
*
|
||||
* @param string $mode install|verify
|
||||
* @return self instancja klasy
|
||||
*/
|
||||
public static function getInstance($mode = 'install')
|
||||
{
|
||||
if (!isset(self::$instance[$mode]))
|
||||
{
|
||||
$class = __CLASS__;
|
||||
self::$instance[$mode] = new $class($mode);
|
||||
}
|
||||
|
||||
return self::$instance[$mode];
|
||||
}
|
||||
|
||||
/**
|
||||
* Konstruktor. Inicuje konfiguracje.
|
||||
*
|
||||
* @param string $mode (install|verify)
|
||||
*/
|
||||
public function __construct($mode = 'install')
|
||||
{
|
||||
$this->mode = $mode;
|
||||
$this->pearDir = sfConfig::get('sf_root_dir') . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR . 'src';
|
||||
$this->pearCfg = $this->pearDir . DIRECTORY_SEPARATOR . '.pearrc';
|
||||
if (!$this->isOptimized()) $this->optimize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Odczytuje listę pakietów zainstalowanych dla danego kanału wraz z informacjami o tych pakietach.
|
||||
*
|
||||
* @param string $channel nazwa kanału PEAR
|
||||
* @return array Dane PEAR dla wszystkich zainstalowanych pakietów. array('stName'=>array(...))
|
||||
*/
|
||||
public function getChannelPackages($channel)
|
||||
{
|
||||
// path/install/src/.registry/.channel.__uri
|
||||
$pearDir = $this->getPearRegistryDir() . DIRECTORY_SEPARATOR . '.channel.' . $channel;
|
||||
$packagesReg = stFile::ls($pearDir);
|
||||
|
||||
$packages = array();
|
||||
|
||||
foreach ($packagesReg as $package)
|
||||
{
|
||||
// sprawdz czy istnieje plik w ST_APP_REGISTRY_MD5SUM
|
||||
if ((file_exists(ST_APP_REGISTRY_MD5SUM . DIRECTORY_SEPARATOR . $package)) && ($this->mode == 'verify'))
|
||||
{
|
||||
// registry przed synchronizacja
|
||||
$filereg = ST_APP_REGISTRY_MD5SUM . DIRECTORY_SEPARATOR . $package;
|
||||
}
|
||||
else
|
||||
{
|
||||
// registry plikow niesynchornizowanych (np. po upgrade z wczesniejszej wersji)
|
||||
// od soteshop 5.0.1 ten element nie powinien byc wykonywany, gdyż dane są odczytywane z kopii registers
|
||||
// ten fragment kodu MUSI pozostać dla zachowania zgodności wersji poprzednich
|
||||
$filereg = $pearDir . DIRECTORY_SEPARATOR . $package;
|
||||
}
|
||||
$data = stFile::read($filereg);
|
||||
$info = @unserialize($data);
|
||||
|
||||
if ($info)
|
||||
{
|
||||
$packages[$info['name']] = array(
|
||||
'summary' => $info['summary'],
|
||||
'version' => $info['version']['release'],
|
||||
'files' => $info['contents']['dir']['file'],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $packages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwraca ścieżkę do plików registry
|
||||
*/
|
||||
public function getPearRegistryDir()
|
||||
{
|
||||
return $this->pearDir . DIRECTORY_SEPARATOR . '.registry';
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwaraca plik register dla danego pliku
|
||||
*
|
||||
* @param string $app aplikacja
|
||||
* @return string ścieżka bezwzględna do pliku regiter eg /path/.register/.channel/pear.sote.pl/stproduct.reg
|
||||
*/
|
||||
public function getPearRegistryFile($app)
|
||||
{
|
||||
$appfile = strtolower($app) . '.reg';
|
||||
$files = sfFinder::type('file')->name($appfile)->in($this->getPearRegistryDir());
|
||||
if (sizeof($files) == 1)
|
||||
{
|
||||
return $files[0];
|
||||
}
|
||||
else return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Odczytuje listę zainstalowanych pakietów (z optymalizacji)
|
||||
*
|
||||
* @param string $mode ST_PEAR_OPT_SUMMARY, ST_PEAR_OPT_VERSIONS
|
||||
* @return array
|
||||
*/
|
||||
static public function getOptPackages($mode = ST_PEAR_OPT_SUMMARY)
|
||||
{
|
||||
if (!self::isOptimized())
|
||||
{
|
||||
stPearInfo::getInstance()->optimize();
|
||||
}
|
||||
|
||||
return unserialize(file_get_contents($mode));
|
||||
}
|
||||
|
||||
/**
|
||||
* Odczytuje listę zainstalowanych pakietów z PEAR
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPackages()
|
||||
{
|
||||
if (null === $this->packages)
|
||||
{
|
||||
$this->packages = self::getOptPackages(ST_PEAR_OPT_SUMMARY);
|
||||
}
|
||||
|
||||
return $this->packages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Odczytuje listę zainstalowanych pakietów
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPackagesVersions()
|
||||
{
|
||||
if (null === $this->versions)
|
||||
{
|
||||
$this->versions = self::getOptPackages(ST_PEAR_OPT_VERSIONS);
|
||||
}
|
||||
|
||||
return $this->versions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Odczytaj wersję aplikacji
|
||||
*
|
||||
* @param string $package
|
||||
* @return string wersja np. '1.0.2'
|
||||
*/
|
||||
public function getPackageVersion($package)
|
||||
{
|
||||
$versions = $this->getPackagesVersions();
|
||||
return isset($versions[$package]) ? $versions[$package] : null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Odczytuje nazwę pakietu wg podanego pliku/kataogu.
|
||||
*
|
||||
* @param string $file np. web/css/backend/smCefarmAskAdviserPlugin.css
|
||||
* @return string package name
|
||||
*/
|
||||
public function getPackage($file)
|
||||
{
|
||||
foreach ($this->getPearPackages() as $package => $data)
|
||||
{
|
||||
foreach ($data['files'] as $fileData)
|
||||
{
|
||||
$dfile = $fileData['attribs']['name'];
|
||||
if (strpos($dfile, $file) !== false) return $package;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Odczytuje listę plików dla pakietu
|
||||
*
|
||||
* @param string $package
|
||||
* @return array
|
||||
*/
|
||||
public function getFiles($package)
|
||||
{
|
||||
$packages = $this->getPearPackages();
|
||||
|
||||
if (!empty($packages[$package]['files']))
|
||||
{
|
||||
return $packages[$package]['files'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sprawdza czy dany pakiet jest zainstalowany.
|
||||
*
|
||||
* @param string $package Nazwa pakietu.
|
||||
* @return bool
|
||||
*/
|
||||
public function isInstalled($package)
|
||||
{
|
||||
$packages = $this->getPackages();
|
||||
|
||||
return isset($packages[$package]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Odczytuje numer wersji zainstalowanego pakietu.
|
||||
*
|
||||
* @param string $pqackage Nazwa pakietu.
|
||||
* @return string Numer wersji.
|
||||
*/
|
||||
public function getVersion($package)
|
||||
{
|
||||
return $this->getPackageVersion($package);
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwaraca dane z .pearrc
|
||||
* Array
|
||||
* (
|
||||
* [php_dir] => /Users/marek/Web/soteshop.502//install/src
|
||||
* [data_dir] => /Users/marek/Web/soteshop.502//install/src
|
||||
* [www_dir] => /Users/marek/Web/soteshop.502//install/src
|
||||
* [cfg_dir] => /Users/marek/Web/soteshop.502//install/src
|
||||
* [ext_dir] => /Users/marek/Web/soteshop.502//install/src
|
||||
* [doc_dir] => /Users/marek/Web/soteshop.502//install/src
|
||||
* [test_dir] => /Users/marek/Web/soteshop.502//install/src
|
||||
* [cache_dir] => /Users/marek/Web/soteshop.502//install/cache
|
||||
* [download_dir] => /Users/marek/Web/soteshop.502//install/download
|
||||
* [temp_dir] => /Users/marek/Web/soteshop.502//install/cache
|
||||
* [bin_dir] => /Users/marek/Web/soteshop.502//install/src
|
||||
* [__channels] => Array
|
||||
* (
|
||||
* [pecl.php.net] => Array
|
||||
* (
|
||||
* )
|
||||
*
|
||||
* [__uri] => Array
|
||||
* (
|
||||
* )
|
||||
*
|
||||
* [pear.dev.quad.sote.pl] => Array
|
||||
* (
|
||||
* )
|
||||
*
|
||||
* )
|
||||
*
|
||||
* [cache_ttl] => 3600
|
||||
* [php_bin] => php
|
||||
* [preferred_state] => stable
|
||||
* [umask] => 18
|
||||
* [default_channel] => pear.dev.quad.sote.pl
|
||||
* )
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPearrc()
|
||||
{
|
||||
$rawdata = stFile::read($this->pearCfg);
|
||||
if (preg_match("/^\#/", $rawdata))
|
||||
{
|
||||
$reg = preg_split("/\n/", $rawdata);
|
||||
$this->pearrcVersionHead = $reg[0];
|
||||
$rawdata = $reg[1];
|
||||
}
|
||||
$result = @unserialize($rawdata);
|
||||
if (is_array($result))
|
||||
{
|
||||
return $result;
|
||||
}
|
||||
else return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwaraca listę kanałów PEAR.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getChannels()
|
||||
{
|
||||
$data = $this->getPearrc();
|
||||
foreach ($data['__channels'] as $channel => $val)
|
||||
{
|
||||
if (!preg_match("/php.net/", $channel))
|
||||
{
|
||||
$channels[] = $channel;
|
||||
}
|
||||
}
|
||||
return $channels;
|
||||
}
|
||||
|
||||
/**
|
||||
* Odczytuje domyślny kanał PEAR
|
||||
*/
|
||||
public function getDefaultChannel()
|
||||
{
|
||||
$data = $this->getPearrc();
|
||||
return $data['default_channel'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Aktualizuje ścieżki w konfiguracji PEAR.
|
||||
* Zmienia wartosci:
|
||||
* [php_dir] => /Users/marek/Web/soteshop.502//install/src
|
||||
* [data_dir] => /Users/marek/Web/soteshop.502//install/src
|
||||
* [www_dir] => /Users/marek/Web/soteshop.502//install/src
|
||||
* [cfg_dir] => /Users/marek/Web/soteshop.502//install/src
|
||||
* [ext_dir] => /Users/marek/Web/soteshop.502//install/src
|
||||
* [doc_dir] => /Users/marek/Web/soteshop.502//install/src
|
||||
* [test_dir] => /Users/marek/Web/soteshop.502//install/src
|
||||
* [cache_dir] => /Users/marek/Web/soteshop.502//install/cache
|
||||
* [download_dir] => /Users/marek/Web/soteshop.502//install/download
|
||||
* [temp_dir] => /Users/marek/Web/soteshop.502//install/cache
|
||||
* [bin_dir] => /Users/marek/Web/soteshop.502//install/src
|
||||
*/
|
||||
public function updateConfig()
|
||||
{
|
||||
$data = $this->getPearrc();
|
||||
$data2 = $data;
|
||||
$sf_root_dir = sfConfig::get('sf_root_dir');
|
||||
|
||||
$path = $sf_root_dir . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR;
|
||||
foreach ($data as $key => $value)
|
||||
{
|
||||
switch ($key)
|
||||
{
|
||||
case "php_dir":
|
||||
case "data_dir":
|
||||
case "www_dir":
|
||||
case "cfg_dir":
|
||||
case "ext_dir":
|
||||
case "doc_dir":
|
||||
case "bin_dir":
|
||||
case "test_dir":
|
||||
$data2[$key] = $path . 'src';
|
||||
break;
|
||||
case "temp_dir":
|
||||
case "cache_dir":
|
||||
$data2[$key] = $path . 'cache';
|
||||
break;
|
||||
case "download_dir":
|
||||
$data2[$key] = $path . 'download';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$raw = serialize($data2);
|
||||
$src = $this->pearrcVersionHead . "\n" . $raw;
|
||||
if (file_put_contents($this->pearCfg, $src))
|
||||
{
|
||||
$data_test = $this->getPearrc();
|
||||
if (is_array($data_test)) return true;
|
||||
else throw new Exception('Wrong PEARRC format in file:' . $this->pearCfg);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception('Can\'t write data to file:' . $this->pearCfg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwaraca informacje czy zostały zapisane dane optymalizacyjne
|
||||
* @return bool
|
||||
*/
|
||||
static public function isOptimized()
|
||||
{
|
||||
if ((!file_exists(ST_PEAR_OPT_SUMMARY)) || (!file_exists(ST_PEAR_OPT_VERSIONS))) return false;
|
||||
else return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optymalizuje plik bazy pakietów. Zapisuje tylko aplikacje nazwy i wersje w osobnych plikach.
|
||||
* @return true
|
||||
*/
|
||||
public function optimize()
|
||||
{
|
||||
$summary = array();
|
||||
$versions = array();
|
||||
|
||||
foreach ($this->getPearPackages() as $package => $data)
|
||||
{
|
||||
$summary[$package] = $data['summary'];
|
||||
$versions[$package] = $data['version'];
|
||||
}
|
||||
|
||||
if (!file_put_contents(ST_PEAR_OPT_SUMMARY, serialize($summary)))
|
||||
{
|
||||
throw new Exception("Unable save file " . ST_PEAR_OPT_SUMMARY);
|
||||
}
|
||||
|
||||
if (!file_put_contents(ST_PEAR_OPT_VERSIONS, serialize($versions)))
|
||||
{
|
||||
throw new Exception("Unable save file " . ST_PEAR_OPT_VERSIONS);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function getPearPackages()
|
||||
{
|
||||
if (null === $this->pearPackages)
|
||||
{
|
||||
$channels = $this->getChannels();
|
||||
|
||||
$packages = array();
|
||||
|
||||
foreach ($channels as $channel)
|
||||
{
|
||||
$packages = array_merge($packages, $this->getChannelPackages($channel));
|
||||
}
|
||||
|
||||
$this->pearPackages = $packages;
|
||||
}
|
||||
|
||||
return $this->pearPackages;
|
||||
}
|
||||
}
|
||||
325
plugins/stInstallerPlugin/lib/stPropelDataLoader.php
Normal file
325
plugins/stInstallerPlugin/lib/stPropelDataLoader.php
Normal file
@@ -0,0 +1,325 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This class interacts with the data source
|
||||
* and loads data.
|
||||
*
|
||||
* @package symfony
|
||||
* @subpackage addon
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @version SVN: $Id: sfPropelData.class.php 662 2009-09-21 12:14:20Z marcin $
|
||||
*/
|
||||
class stPropelDataLoader
|
||||
{
|
||||
|
||||
protected $data = array();
|
||||
protected $fixtureMap = array();
|
||||
protected $moduleIndex = array();
|
||||
protected $maps = array();
|
||||
protected $processed = array();
|
||||
protected $deletedClasses = array();
|
||||
protected $objectReferences = array();
|
||||
|
||||
public function loadData($fixture_dir_or_file, $delay = 0)
|
||||
{
|
||||
$fixture_files = $this->getFixtureFiles($fixture_dir_or_file);
|
||||
|
||||
foreach ($fixture_files as $fixture_file)
|
||||
{
|
||||
$this->doLoadData($fixture_file, $delay);
|
||||
}
|
||||
|
||||
return $fixture_files;
|
||||
}
|
||||
|
||||
protected function doLoadData($fixture_file, $delay = 0)
|
||||
{
|
||||
if (!isset($this->processed[$fixture_file]))
|
||||
{
|
||||
$this->doDeleteCurrentData($fixture_file);
|
||||
|
||||
$data = $this->loadFixtureFromFile($fixture_file);
|
||||
|
||||
$this->processed[$fixture_file] = true;
|
||||
|
||||
$this->loadDataFromArray($data, $delay);
|
||||
}
|
||||
}
|
||||
|
||||
public function loadDataFromArray($data, $delay = 0)
|
||||
{
|
||||
if ($data === null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($data as $class => $datas)
|
||||
{
|
||||
$class = trim($class);
|
||||
|
||||
$peer_class = $class.'Peer';
|
||||
|
||||
$this->loadMapBuilder($class);
|
||||
|
||||
$tableMap = $this->maps[$class]->getDatabaseMap()->getTable(constant($peer_class.'::TABLE_NAME'));
|
||||
|
||||
$column_names = array_flip(call_user_func_array(array($peer_class, 'getFieldNames'), array(BasePeer::TYPE_FIELDNAME)));
|
||||
|
||||
if (!is_array($datas))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!is_subclass_of($class, 'BaseObject'))
|
||||
{
|
||||
throw new Exception(sprintf('The class "%s" is not a Propel class. This probably means there is already a class named "%s" somewhere in symfony or in your project.', $class, $class));
|
||||
}
|
||||
|
||||
foreach ($datas as $key => $data)
|
||||
{
|
||||
$obj = new $class();
|
||||
|
||||
if (!is_array($data))
|
||||
{
|
||||
throw new Exception(sprintf('You must give a name for each fixture data entry (class %s)', $class));
|
||||
}
|
||||
|
||||
foreach ($data as $name => $value)
|
||||
{
|
||||
$isARealColumn = true;
|
||||
|
||||
try
|
||||
{
|
||||
$column = $tableMap->getColumn($name);
|
||||
}
|
||||
catch (PropelException $e)
|
||||
{
|
||||
$isARealColumn = false;
|
||||
}
|
||||
|
||||
// foreign key?
|
||||
if ($isARealColumn)
|
||||
{
|
||||
if ($column->isForeignKey() && !is_null($value))
|
||||
{
|
||||
list($relatedObjectName) = explode("_", $value);
|
||||
|
||||
if (!isset($this->objectReferences[$value]))
|
||||
{
|
||||
if (!$this->loadFixturesFromClassName($relatedObjectName))
|
||||
{
|
||||
throw new sfException(sprintf('Failed when trying to locate the object "%s" from class "%2$s" or "%2$s.yml" fixture file', $value, $relatedObjectName));
|
||||
}
|
||||
|
||||
if (!isset($this->objectReferences[$value]))
|
||||
{
|
||||
if (in_array($value, array('Countries_39', 'Currency_5', 'Countries_6')))
|
||||
{
|
||||
continue 2;
|
||||
}
|
||||
|
||||
throw new sfException(sprintf('The object "%s" from class "%s" is not defined in your data file.', $value, $relatedObjectName));
|
||||
}
|
||||
}
|
||||
|
||||
$value = $this->objectReferences[$value];
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($column_names[$name]))
|
||||
{
|
||||
$obj->setByPosition($column_names[$name], $value);
|
||||
}
|
||||
else if (is_callable(array($obj, $method = 'set'.sfInflector::camelize($name))))
|
||||
{
|
||||
$obj->$method($value);
|
||||
}
|
||||
else
|
||||
{
|
||||
$error = 'Column "%s" does not exist for class "%s"';
|
||||
|
||||
$error = sprintf($error, $name, $class);
|
||||
|
||||
throw new sfException($error);
|
||||
}
|
||||
}
|
||||
|
||||
$obj->save();
|
||||
|
||||
if (method_exists($obj, 'getPrimaryKey'))
|
||||
{
|
||||
$this->objectReferences[$key] = $obj->getPrimaryKey();
|
||||
}
|
||||
|
||||
$this->delay($delay);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function doDeleteCurrentData($fixture_file)
|
||||
{
|
||||
$data = $this->loadFixtureFromFile($fixture_file);
|
||||
|
||||
if ($data === null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$classes = array_keys($data);
|
||||
|
||||
krsort($classes);
|
||||
|
||||
foreach ($classes as $class)
|
||||
{
|
||||
$class = trim($class);
|
||||
|
||||
if (isset($this->deletedClasses[$class]))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$peer_class = $class.'Peer';
|
||||
|
||||
if (!$classPath = sfCore::getClassPath($peer_class))
|
||||
{
|
||||
throw new sfException(sprintf('Unable to find path for class "%s".', $peer_class));
|
||||
}
|
||||
|
||||
require_once($classPath);
|
||||
|
||||
call_user_func(array($peer_class, 'doDeleteAll'));
|
||||
|
||||
$this->deletedClasses[$class] = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected function loadMapBuilder($class)
|
||||
{
|
||||
$mapBuilderClass = $class.'MapBuilder';
|
||||
|
||||
if (!isset($this->maps[$class]))
|
||||
{
|
||||
if (!$classPath = sfCore::getClassPath($mapBuilderClass))
|
||||
{
|
||||
throw new sfException(sprintf('Unable to find path for class "%s".', $mapBuilderClass));
|
||||
}
|
||||
|
||||
require_once($classPath);
|
||||
|
||||
$this->maps[$class] = new $mapBuilderClass();
|
||||
|
||||
$this->maps[$class]->doBuild();
|
||||
}
|
||||
}
|
||||
|
||||
public function indexFixturesFiles($fixtures_dirs = array(), $delay = 0)
|
||||
{
|
||||
foreach ($fixtures_dirs as $dir)
|
||||
{
|
||||
$files = $this->getFiles($dir);
|
||||
|
||||
sort($files);
|
||||
|
||||
$this->fixtureMap[$dir] = $files;
|
||||
|
||||
foreach ($files as $file)
|
||||
{
|
||||
$this->indexFixtureFile($file);
|
||||
}
|
||||
|
||||
$this->delay($delay);
|
||||
}
|
||||
}
|
||||
|
||||
protected function delay($ms = 0)
|
||||
{
|
||||
if ($ms)
|
||||
{
|
||||
usleep($ms * 1000);
|
||||
}
|
||||
}
|
||||
|
||||
protected function indexFixtureFile($file)
|
||||
{
|
||||
$data = sfYaml::load($file);
|
||||
|
||||
$model_classes = array_keys($data);
|
||||
|
||||
foreach ($model_classes as $model_class)
|
||||
{
|
||||
if (!isset($this->modelIndex[$model_class]))
|
||||
{
|
||||
$this->modelIndex[$model_class] = array();
|
||||
}
|
||||
|
||||
$this->modelIndex[$model_class][] = $file;
|
||||
}
|
||||
|
||||
$this->data[$file] = $data;
|
||||
|
||||
unset($data);
|
||||
}
|
||||
|
||||
protected function loadFixtureFromFile($fixture_file)
|
||||
{
|
||||
if (!isset($this->data[$fixture_file]))
|
||||
{
|
||||
$this->indexFixtureFile($fixture_file);
|
||||
}
|
||||
|
||||
return $this->data[$fixture_file];
|
||||
}
|
||||
|
||||
protected function loadFixturesFromClassName($classname)
|
||||
{
|
||||
if (isset($this->modelIndex[$classname]))
|
||||
{
|
||||
foreach ($this->modelIndex[$classname] as $file)
|
||||
{
|
||||
$this->doLoadData($file);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function getFixtureFiles($dir_or_file)
|
||||
{
|
||||
if (isset($this->fixtureMap[$dir_or_file]))
|
||||
{
|
||||
return $this->fixtureMap[$dir_or_file];
|
||||
}
|
||||
|
||||
return array($dir_or_file);
|
||||
}
|
||||
|
||||
protected function getFiles($directory_or_file = null)
|
||||
{
|
||||
// directory or file?
|
||||
$fixture_files = array();
|
||||
if (!$directory_or_file)
|
||||
{
|
||||
$directory_or_file = sfConfig::get('sf_data_dir').'/fixtures';
|
||||
}
|
||||
|
||||
if (is_file($directory_or_file))
|
||||
{
|
||||
$fixture_files[] = $directory_or_file;
|
||||
}
|
||||
else if (is_dir($directory_or_file))
|
||||
{
|
||||
$fixture_files = sfFinder::type('file')->ignore_version_control()->maxdepth(0)->name('*.yml')->in($directory_or_file);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new sfInitializationException('You must give a directory or a file.');
|
||||
}
|
||||
|
||||
return $fixture_files;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* SOTESHOP/stInstallerPlugin
|
||||
*
|
||||
* Ten plik należy do aplikacji stInstallerPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
|
||||
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
|
||||
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
|
||||
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
|
||||
*
|
||||
* @package stInstallerPlugin
|
||||
* @subpackage libs
|
||||
* @copyright SOTE (www.sote.pl)
|
||||
* @license http://www.sote.pl/license/open (Open License SOTE) Otwarta Licencja SOTE
|
||||
* @version $Id: stPropelGeneratorController.class.php 3782 2010-03-05 13:39:42Z marek $
|
||||
* @author Marcin Butlak <marcin.butlak@sote.pl>
|
||||
*/
|
||||
require_once sfConfig::get('sf_symfony_lib_dir').'/vendor/pake/pakeColor.class.php';
|
||||
/**
|
||||
* Klasa umożliwiająca kontrolę nad przebiegiem generowania bazy danych na podstawie schematów *schema.yml
|
||||
*
|
||||
* @package stInstallerPlugin
|
||||
* @subpackage libs
|
||||
* @author Marcin Butlak <marcin.butlak@sote.pl>
|
||||
*/
|
||||
class stPropelGeneratorController
|
||||
{
|
||||
|
||||
/**
|
||||
* Flaga - buduj bazę danych na podstawie informacji z pliku package-schema-diff.yml
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected static $schemaDiffBuildControl = false;
|
||||
/**
|
||||
* Flaga - usuwaj tabele podczas ich tworzenia
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected static $dropStatements = true;
|
||||
protected static $forceRebuild = false;
|
||||
|
||||
public static function forceRebuild()
|
||||
{
|
||||
self::$forceRebuild = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wyłącz usuwanie tabel podczas ich tworzenia
|
||||
*
|
||||
*/
|
||||
public static function disableDropStatements()
|
||||
{
|
||||
self::showInfo('disabling', 'drop statements on table creation');
|
||||
|
||||
self::$dropStatements = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Włącz usuwanie tabel podczas ich tworzenia
|
||||
*
|
||||
*/
|
||||
public static function enableDropStatements()
|
||||
{
|
||||
self::showInfo('enabling', 'drop statements on table creation');
|
||||
|
||||
self::$dropStatements = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wyłącz budowanie bazy danych na podstawie informacji z pliku package-schema-diff.yml
|
||||
*
|
||||
*/
|
||||
public static function disableSchemaDiffBuildControl()
|
||||
{
|
||||
self::showInfo('disabling', 'schema difference build control');
|
||||
|
||||
self::$schemaDiffBuildControl = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Włącz budowanie bazy danych na podstawie informacji z pliku package-schema-diff.yml
|
||||
*
|
||||
*/
|
||||
public static function enableSchemaDiffBuildControl()
|
||||
{
|
||||
self::showInfo('enabling', 'schema difference build control');
|
||||
|
||||
self::$schemaDiffBuildControl = true;
|
||||
}
|
||||
|
||||
public static function isSchemaDiffBuildControl()
|
||||
{
|
||||
return self::$schemaDiffBuildControl;
|
||||
}
|
||||
|
||||
public static function isDropStatements()
|
||||
{
|
||||
return self::$dropStatements;
|
||||
}
|
||||
|
||||
public static function getPluginDirs()
|
||||
{
|
||||
static $plugin_dirs = null;
|
||||
|
||||
if (null === $plugin_dirs)
|
||||
{
|
||||
$plugin_dirs = glob(sfConfig::get('sf_plugins_dir').DIRECTORY_SEPARATOR.'*');
|
||||
}
|
||||
|
||||
return $plugin_dirs;
|
||||
}
|
||||
|
||||
public static function isDatabaseRebuildNeeded()
|
||||
{
|
||||
return self::$forceRebuild || is_file(sfConfig::get('sf_config_dir').DIRECTORY_SEPARATOR.'schema-diff.yml');
|
||||
}
|
||||
|
||||
public static function isForced()
|
||||
{
|
||||
return self::$forceRebuild;
|
||||
}
|
||||
|
||||
protected static function showInfo($action, $message)
|
||||
{
|
||||
if (pakeApp::get_instance()->get_verbose())
|
||||
{
|
||||
pakeColor::style('GENERATOR_INFO', array('fg' => 'blue'));
|
||||
$width = 9 + strlen(pakeColor::colorize('', 'GENERATOR_INFO'));
|
||||
echo sprintf('>> %-'.$width.'s %s', pakeColor::colorize($action, 'GENERATOR_INFO'), $message)."\n";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
240
plugins/stInstallerPlugin/lib/stRegisterSync.class.php
Normal file
240
plugins/stInstallerPlugin/lib/stRegisterSync.class.php
Normal file
@@ -0,0 +1,240 @@
|
||||
<?php
|
||||
/**
|
||||
* SOTESHOP/stInstallerPlugin
|
||||
*
|
||||
* Ten plik należy do aplikacji stInstallerPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
|
||||
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
|
||||
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
|
||||
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
|
||||
*
|
||||
* @package stInstallerPlugin
|
||||
* @subpackage libs
|
||||
* @copyright SOTE (www.sote.pl)
|
||||
* @license http://www.sote.pl/license/open (Open License SOTE) Otwarta Licencja SOTE
|
||||
* @version $Id: stRegisterSync.class.php 3782 2010-03-05 13:39:42Z marek $
|
||||
* @author Marek Jakubowicz <marek.jakubowicz@sote.pl>
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plik z bazą danych synchronizowanych aplikacji.
|
||||
* @deprecated since stInstallerPlugin 1.0.3
|
||||
*/
|
||||
define ("ST_APP_REGISTRY_DB",sfConfig::get('sf_root_dir').DIRECTORY_SEPARATOR.'install'.DIRECTORY_SEPARATOR.'db'.DIRECTORY_SEPARATOR.'.registry.yml');
|
||||
|
||||
/**
|
||||
* Plik z bazą danych synchronizowanych aplikacji.
|
||||
*/
|
||||
define ("ST_APP_REGISTRY_DB2",sfConfig::get('sf_root_dir').DIRECTORY_SEPARATOR.'install'.DIRECTORY_SEPARATOR.'db'.DIRECTORY_SEPARATOR.'.registry.reg');
|
||||
|
||||
/**
|
||||
* Katalog z bazą danych sum kontrolnych
|
||||
*/
|
||||
if (! defined('ST_APP_REGISTRY_MD5SUM'))
|
||||
define ("ST_APP_REGISTRY_MD5SUM",sfConfig::get('sf_root_dir').DIRECTORY_SEPARATOR.'install'.DIRECTORY_SEPARATOR.'db'.DIRECTORY_SEPARATOR.'.md5sum');
|
||||
|
||||
/**
|
||||
* Obsługuje dane synchronizacji zapisane w pliku.
|
||||
*
|
||||
* @package stInstallerPlugin
|
||||
* @subpackage libs
|
||||
*/
|
||||
class stRegisterSync
|
||||
{
|
||||
/**
|
||||
* @var string plik z bazą danych synchornizowanych aplikacji
|
||||
*/
|
||||
var $registryFile;
|
||||
|
||||
/**
|
||||
* @var stInstaller
|
||||
*/
|
||||
var $installer;
|
||||
|
||||
/**
|
||||
* Konstruktor.
|
||||
*/
|
||||
public function __construct($file=ST_APP_REGISTRY_DB2)
|
||||
{
|
||||
$this->peari = stPearInfo::getInstance();
|
||||
$this->registryFile=$file;
|
||||
$this->installer = new stInstaller();
|
||||
$this->history = new stInstallerHistory();
|
||||
$this->fixmd5sum();
|
||||
}
|
||||
|
||||
/**
|
||||
* Zapisz w bazie informacje o zainstalowaniu aplikacji.
|
||||
* Baza danych aplikacji install/db/.registry.reg
|
||||
*
|
||||
* @param string $app nazwa aplikacji
|
||||
* @return bool
|
||||
*/
|
||||
public function register($app)
|
||||
{
|
||||
$version=$this->peari->getPackageVersion($app);
|
||||
|
||||
if (empty($version)) $action='uninstall';
|
||||
else $action='install';
|
||||
|
||||
$registry=$this->getData();
|
||||
|
||||
switch ($action)
|
||||
{
|
||||
case "install":
|
||||
|
||||
if ($this->registerMd5sum($app))
|
||||
{
|
||||
$registry['packages'][$app]=$version;
|
||||
}
|
||||
|
||||
break;
|
||||
case "uninstall":
|
||||
if ($this->unregisterMd5sum($app))
|
||||
{
|
||||
unset($registry['packages'][$app]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// $ret=stFile::write($this->registryFile,sfYaml::dump($registry));
|
||||
$ret=stFile::write($this->registryFile,serialize($registry));
|
||||
|
||||
$this->history->add($app,$version); // dodaj do historii aktualizacji
|
||||
$this->history->save(); // zapisz po każdej aktualizacji, na wypadek przerwania aktualizacji
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Odczytuje dane z pliku i zwaraca tablicę.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static public function getData()
|
||||
{
|
||||
$registry=array();
|
||||
if (file_exists(ST_APP_REGISTRY_DB2))
|
||||
{
|
||||
// update z wersji 1.0.2 do 1.0.3, zmiana lokalizacji pliku danych
|
||||
// system za pierwszym razem odczytuje dane ze starego pliku a zapisuje w nowym
|
||||
if (! file_exists(ST_APP_REGISTRY_DB2)) $data=sfYaml::load(ST_APP_REGISTRY_DB2);
|
||||
else {
|
||||
if (file_exists(ST_APP_REGISTRY_DB)) unlink(ST_APP_REGISTRY_DB); // usun stary plik z werjsi 1.0.2
|
||||
$data=unserialize(file_get_contents(ST_APP_REGISTRY_DB2));
|
||||
}
|
||||
|
||||
if (! empty($data)) $registry=$data;
|
||||
} else {
|
||||
if (file_exists(ST_APP_REGISTRY_DB))
|
||||
{
|
||||
$data=sfYaml::load(ST_APP_REGISTRY_DB);
|
||||
if (! empty($data)) $registry=$data;
|
||||
}
|
||||
}
|
||||
return $registry;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Odczytaj listę aplikacji
|
||||
*
|
||||
* @return array array('stAppName'=>'1.0.2','stTest'=>'1.0.0',...)
|
||||
*/
|
||||
static public function getSynchronizedApps()
|
||||
{
|
||||
$data=self::getData();
|
||||
if (is_array($data['packages'])) return $data['packages'];
|
||||
else return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Odczytuje wersje zsynchronizowanej wersji aplikacji
|
||||
*
|
||||
* @return string|null np. 1.0.2
|
||||
* @todo prztestować
|
||||
*/
|
||||
static public function getPackageVersion($app)
|
||||
{
|
||||
$apps=self::getSynchronizedApps();
|
||||
if (! empty($apps[$app])) return $apps[$app];
|
||||
else return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwraca listę aplikacji so synchronizacji
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function getAppsToSync()
|
||||
{
|
||||
$apps_pear=$this->installer->getInstalledApps();
|
||||
$apps_sync=$this->getSynchronizedApps();
|
||||
$changes=st_array_diff($apps_sync,$apps_pear);
|
||||
return $changes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rejestruje sumy kontrolne plików aplikacji
|
||||
*
|
||||
* @param string $app aplikacja
|
||||
* @return bool
|
||||
*/
|
||||
private function registerMd5Sum($app)
|
||||
{
|
||||
pake_echo ("Registering md5sum for $app");
|
||||
$file = new stFile();
|
||||
$filereg=$this->peari->getPearRegistryFile($app);
|
||||
if (! is_dir(ST_APP_REGISTRY_MD5SUM)) {
|
||||
|
||||
$file->mkdir(ST_APP_REGISTRY_MD5SUM);
|
||||
}
|
||||
$regfiledb=ST_APP_REGISTRY_MD5SUM.DIRECTORY_SEPARATOR.basename($filereg);
|
||||
$file->copy($filereg,$regfiledb);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Usuwa dane sum kontrolnych aplikacji
|
||||
*
|
||||
* @param string $app aplikacja
|
||||
* @return bool
|
||||
*/
|
||||
private function unregisterMd5Sum($app)
|
||||
{
|
||||
pake_echo ("Unregistering md5sum for $app");
|
||||
$file = new stFile();
|
||||
$filereg=strtolower($app).'.reg';
|
||||
$regfiledb=ST_APP_REGISTRY_MD5SUM.DIRECTORY_SEPARATOR.basename($filereg);
|
||||
if (file_exists($regfiledb))
|
||||
{
|
||||
if ($file->rm($regfiledb)) return true;
|
||||
else return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fix soteshop 5.0.0 -> 5.0.1
|
||||
* Dodaje bazę install/db/.md5sum. Baza może być dodana przez kopiowanie TYLKO 1 raz, jeśli nie istnieje,
|
||||
* lub zostanie błędnie usunięta.
|
||||
*/
|
||||
static public function fixmd5sum()
|
||||
{
|
||||
if (! is_dir(ST_APP_REGISTRY_MD5SUM))
|
||||
{
|
||||
$peari = stPearInfo::getInstance();
|
||||
$file = new stFile();
|
||||
$dir=$peari->getPearRegistryDir();
|
||||
$apps=sfFinder::type('file')->name('*.reg')->in($dir);
|
||||
if ($file->mkdir(ST_APP_REGISTRY_MD5SUM))
|
||||
{
|
||||
foreach ($apps as $regfile)
|
||||
{
|
||||
$file->copy($regfile,ST_APP_REGISTRY_MD5SUM.DIRECTORY_SEPARATOR.basename($regfile));
|
||||
}
|
||||
} else throw new Exception('Can\'t make directory '.$dir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/**
|
||||
* SOTESHOP/stInstallerPlugin
|
||||
*
|
||||
* Ten plik należy do aplikacji stInstallerPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
|
||||
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
|
||||
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
|
||||
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
|
||||
*
|
||||
* @package stInstallerPlugin
|
||||
* @subpackage libs
|
||||
* @copyright SOTE (www.sote.pl)
|
||||
* @license http://www.sote.pl/license/open (Open License SOTE) Otwarta Licencja SOTE
|
||||
* @version $Id: stServerExecutionTime.class.php 3782 2010-03-05 13:39:42Z marek $
|
||||
* @author Daniel Mendalka <daniel.mendalka@sote.pl>
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package stInstallerPlugin
|
||||
* @subpackage libs
|
||||
*/
|
||||
class stServerExecutionTime
|
||||
{
|
||||
|
||||
/**
|
||||
* @var integer Ile czasu jest wymagane w sekundach.
|
||||
*/
|
||||
var $max = 60;
|
||||
|
||||
/**
|
||||
* Ustawia wymagany czas do wykonania skryptu.
|
||||
*
|
||||
* @param integer
|
||||
*/
|
||||
public function setMax($new_max)
|
||||
{
|
||||
$this->max = $new_max;
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwraca zapisany czasy wymagany do wykonania skryptu.
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getMax()
|
||||
{
|
||||
return $this->max;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sprawdza czy wymagany czas wykonywania skryptu jest mnieszy
|
||||
* niż dozwolony na serwerze.
|
||||
*
|
||||
* @return boolen
|
||||
*/
|
||||
public function check()
|
||||
{
|
||||
if ($this->getServerTime() == 0) return true;
|
||||
return $this->getServerTime() >= $this->getMax();
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwraca dozwolony czas wykonywania skryptu na serwerze.
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getServerTime()
|
||||
{
|
||||
return ini_get('max_execution_time');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
55
plugins/stInstallerPlugin/lib/stYamlConfig.class.php
Normal file
55
plugins/stInstallerPlugin/lib/stYamlConfig.class.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* SOTESHOP/stInstallerPlugin
|
||||
*
|
||||
* Ten plik należy do aplikacji stInstallerPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
|
||||
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
|
||||
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
|
||||
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
|
||||
*
|
||||
* @package stInstallerPlugin
|
||||
* @subpackage libs
|
||||
* @copyright SOTE (www.sote.pl)
|
||||
* @license http://www.sote.pl/license/open (Open License SOTE) Otwarta Licencja SOTE
|
||||
* @version $Id: stYamlConfig.class.php 3782 2010-03-05 13:39:42Z marek $
|
||||
* @author Marek Jakubowicz <marek.jakubowicz@sote.pl>
|
||||
*/
|
||||
|
||||
/**
|
||||
* Helper tablic PHP.
|
||||
*/
|
||||
require_once (sfConfig::get('sf_plugins_dir').DIRECTORY_SEPARATOR.'stInstallerPlugin'.DIRECTORY_SEPARATOR.'lib'.DIRECTORY_SEPARATOR.'helper'.DIRECTORY_SEPARATOR.'stArrayHelper.php');
|
||||
|
||||
/**
|
||||
* Obsługa plików YAML modyfikowanych przez aplikacje ze strony użytkownika.
|
||||
*
|
||||
* @package stInstallerPlugin
|
||||
* @subpackage libs
|
||||
*/
|
||||
class stYamlConfig {
|
||||
|
||||
/**
|
||||
* Odczytuje plik YAML.
|
||||
* Odczytywany jest wskazany plik np. /path/file.yml i /path/__file.yml
|
||||
*/
|
||||
static public function load($file)
|
||||
{
|
||||
$user_file=dirname($file).DIRECTORY_SEPARATOR.'__'.basename($file);
|
||||
if (file_exists($file)) $dat1=sfYaml::load($file); else $dat1=array();
|
||||
if (file_exists($user_file)) $dat2=sfYaml::load($user_file); else $dat2=array();
|
||||
|
||||
return st_array_merge_recursive3($dat1, $dat2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Zapisuje konfiguracje użytkownika.
|
||||
*/
|
||||
static public function write($file, $data)
|
||||
{
|
||||
$user_file=dirname($file).DIRECTORY_SEPARATOR.'__'.basename($file);
|
||||
$data_dump=sfYaml::dump($data);
|
||||
if (stFile::write($user_file,$data_dump)) return true;
|
||||
else return false;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,324 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* SOTESHOP/stInstallerPlugin
|
||||
*
|
||||
* Ten plik należy do aplikacji stInstallerPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
|
||||
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
|
||||
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
|
||||
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
|
||||
*
|
||||
* @package stInstallerPlugin
|
||||
* @subpackage libs
|
||||
* @copyright SOTE (www.sote.pl)
|
||||
* @license http://www.sote.pl/license/open (Open License SOTE) Otwarta Licencja SOTE
|
||||
* @version $Id: StMysqlDDLBuilder.php 3782 2010-03-05 13:39:42Z marek $
|
||||
* @author Marcin Butlak <marcin.butlak@sote.pl>
|
||||
*/
|
||||
require_once 'propel/engine/builder/sql/mysql/MysqlDDLBuilder.php';
|
||||
|
||||
/**
|
||||
* Rozszerzenie klasy MysqlDDLBuilder - generowanie SQL na podstawie różnicy schema.yml
|
||||
*
|
||||
* @package stInstallerPlugin
|
||||
* @subpackage libs
|
||||
* @author Marcin Butlak <marcin.butlak@sote.pl>
|
||||
*/
|
||||
class StMysqlDDLBuilder extends MysqlDDLBuilder
|
||||
{
|
||||
protected $con = null;
|
||||
|
||||
/**
|
||||
* Załadowane definicje z 'package-schema-diff.yml'
|
||||
* @var array
|
||||
*/
|
||||
public static $tableDiff = null;
|
||||
/**
|
||||
* Lista tabel do utworzenia
|
||||
* @var array
|
||||
*/
|
||||
protected $tableCreateDiff = array();
|
||||
/**
|
||||
* Lista tabel i kolumn do modyfikacji
|
||||
* @var array
|
||||
*/
|
||||
protected $tableAlterDiff = array();
|
||||
|
||||
protected static $indexes = array();
|
||||
|
||||
/**
|
||||
* Przeciążenie konstruktora - załadowanie definicji 'package-schema-diff.yml'
|
||||
*
|
||||
* @param Table $table
|
||||
*/
|
||||
public function __construct(Table $table)
|
||||
{
|
||||
parent::__construct($table);
|
||||
|
||||
if (stPropelGeneratorController::isSchemaDiffBuildControl())
|
||||
{
|
||||
$schema_diff_file = sfConfig::get('sf_config_dir') . DIRECTORY_SEPARATOR . 'schema-diff.yml';
|
||||
|
||||
if (is_null(self::$tableDiff) && is_file($schema_diff_file))
|
||||
{
|
||||
self::$tableDiff = sfYaml::load($schema_diff_file);
|
||||
}
|
||||
|
||||
$this->tableCreateDiff = isset(self::$tableDiff['propel']['create']) ? self::$tableDiff['propel']['create'] : array();
|
||||
|
||||
$this->tableAlterAddDiff = isset(self::$tableDiff['propel']['alter_add']) ? self::$tableDiff['propel']['alter_add'] : array();
|
||||
|
||||
$this->tableAlterChangeDiff = isset(self::$tableDiff['propel']['alter_change']) ? self::$tableDiff['propel']['alter_change'] : array();
|
||||
}
|
||||
}
|
||||
|
||||
public function setCreoleConnection($con)
|
||||
{
|
||||
$this->con = $con;
|
||||
}
|
||||
|
||||
/**
|
||||
* Przeciążenie głównej metody zwracającej SQL
|
||||
*
|
||||
* @return string zapytania SQL
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
if (stPropelGeneratorController::isSchemaDiffBuildControl())
|
||||
{
|
||||
$lines = array();
|
||||
|
||||
if (isset($this->tableCreateDiff[$this->getTable()->getName()]))
|
||||
{
|
||||
$lines[] = parent::build();
|
||||
}
|
||||
|
||||
if (isset($this->tableAlterAddDiff[$this->getTable()->getName()]) || stPropelGeneratorController::isForced())
|
||||
{
|
||||
$this->addAlterHeader($lines);
|
||||
$this->addAlterTable($lines);
|
||||
}
|
||||
|
||||
if (isset($this->tableAlterChangeDiff[$this->getTable()->getName()]))
|
||||
{
|
||||
$this->addAlterHeader($lines);
|
||||
$this->addAlterTable($lines, true);
|
||||
}
|
||||
|
||||
if (isset($this->tableAlterChangeDiff[$this->getTable()->getName()]) || isset($this->tableAlterAddDiff[$this->getTable()->getName()]))
|
||||
{
|
||||
$this->addAlterTableIndex($lines);
|
||||
}
|
||||
|
||||
return implode("\n", $lines);
|
||||
}
|
||||
|
||||
return parent::build();
|
||||
}
|
||||
|
||||
protected function addAlterTableIndex(&$lines)
|
||||
{
|
||||
$table = $this->getTable();
|
||||
|
||||
$platform = $this->getPlatform();
|
||||
|
||||
$con = $this->con;
|
||||
|
||||
$rs = $con->executeQuery("SHOW INDEXES FROM ".$this->quoteIdentifier($table->getName()));
|
||||
|
||||
$index_list = array();
|
||||
|
||||
while($rs->next())
|
||||
{
|
||||
$row = $rs->getRow();
|
||||
if (!isset($index_list[$row['Key_name']]))
|
||||
{
|
||||
$index_list[$row['Key_name']] = $row['Column_name'];
|
||||
}
|
||||
}
|
||||
|
||||
$match_index = implode('|', array_keys($index_list));
|
||||
|
||||
$forgeins = array();
|
||||
|
||||
$this->addForeignKeysLines($forgeins);
|
||||
|
||||
foreach ($forgeins as $forgein)
|
||||
{
|
||||
if (!preg_match('/`('.$match_index.')`/', $forgein))
|
||||
{
|
||||
$alters[] = " ADD ".$forgein;
|
||||
}
|
||||
}
|
||||
|
||||
$indices = array();
|
||||
|
||||
$this->addIndicesLines($indices);
|
||||
|
||||
// Generowanie zapytań alter dla indeksów
|
||||
foreach ($indices as $indice)
|
||||
{
|
||||
if (!preg_match('/`('.$match_index.')`/', $indice))
|
||||
{
|
||||
$alters[] = " ADD ".$indice;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($alters))
|
||||
{
|
||||
$lines[] = "ALTER TABLE ".$this->quoteIdentifier($table->getName()).implode(",", $alters).";\n";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Dodaje zapytania ALTER dla tabeli
|
||||
*
|
||||
* @param array $lines Lista zapytań SQL
|
||||
*/
|
||||
protected function addAlterTable(&$lines, $change = false)
|
||||
{
|
||||
$table = $this->getTable();
|
||||
|
||||
$platform = $this->getPlatform();
|
||||
|
||||
if ($change)
|
||||
{
|
||||
$alter_columns = isset($this->tableAlterChangeDiff[$table->getName()]) ? $this->tableAlterChangeDiff[$table->getName()] : array();
|
||||
}
|
||||
else
|
||||
{
|
||||
$alter_columns = isset($this->tableAlterAddDiff[$table->getName()]) ? $this->tableAlterAddDiff[$table->getName()] : array();
|
||||
}
|
||||
|
||||
$forgeins = array();
|
||||
|
||||
$indices = array();
|
||||
|
||||
$alters = array();
|
||||
|
||||
$primary = array();
|
||||
|
||||
$alterAfterIndex = array();
|
||||
|
||||
// $con = self::getPropelConnection();
|
||||
// $rs = $con->executeQuery("SHOW INDEXES FROM ".$this->quoteIdentifier($table->getName()));
|
||||
|
||||
// $index_list = array();
|
||||
|
||||
// while($rs->next())
|
||||
// {
|
||||
// $row = $rs->getRow();
|
||||
// if (!isset($index_list[$row['Key_name']]))
|
||||
// {
|
||||
// $index_list[$row['Key_name']] = $row['Column_name'];
|
||||
// }
|
||||
// }
|
||||
|
||||
// $match_index = implode('|', array_keys($index_list));
|
||||
|
||||
// Generowanie zapytań ALTER dla kolumn
|
||||
foreach ($table->getColumns() as $col)
|
||||
{
|
||||
if (isset($alter_columns[$col->getName()]))
|
||||
{
|
||||
$entry = $this->getColumnDDL($col);
|
||||
|
||||
if ($col->getDescription())
|
||||
{
|
||||
$entry .= " COMMENT '".$platform->escapeText($col->getDescription())."'";
|
||||
}
|
||||
|
||||
if ($change)
|
||||
{
|
||||
if (isset($alter_columns[$col->getName()]['primaryKey']) && $alter_columns[$col->getName()]['primaryKey'])
|
||||
{
|
||||
$primary[] = $col->getName();
|
||||
}
|
||||
|
||||
if (isset($alter_columns[$col->getName()]['autoIncrement']) && $alter_columns[$col->getName()]['autoIncrement'])
|
||||
{
|
||||
$alterAfterIndex[] = " CHANGE ".$this->quoteIdentifier($col->getName())." ".$entry;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($alter_columns[$col->getName()]['change_column']))
|
||||
{
|
||||
$alters[] = " CHANGE ".$this->quoteIdentifier($alter_columns[$col->getName()]['change_column'])." ".$entry;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($change)
|
||||
{
|
||||
$alters[] = " CHANGE ".$this->quoteIdentifier($col->getName())." ".$entry;
|
||||
}
|
||||
else
|
||||
{
|
||||
$alters[] = " ADD ".$entry;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($primary)
|
||||
{
|
||||
$alters[] = " ADD PRIMARY KEY (".implode(", ", $primary).")";
|
||||
}
|
||||
|
||||
if (!empty($alters) || !empty($alterAfterIndex))
|
||||
{
|
||||
$lines[] = "ALTER TABLE ".$this->quoteIdentifier($table->getName()).implode(",", $alters).($alterAfterIndex ? ($alters ? "," : " ").implode(",", $alterAfterIndex) : "").";\n";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Dodaje komentarz z nagłówkiem dla zapytań ALTER
|
||||
*
|
||||
* @param array $lines Lista zapytań SQL
|
||||
*/
|
||||
protected function addAlterHeader(&$lines)
|
||||
{
|
||||
$lines[] = "";
|
||||
$lines[] = "#-----------------------------------------------------------------------------";
|
||||
$lines[] = "#-- ALTER TABLE ".$this->getTable()->getName();
|
||||
$lines[] = "#-----------------------------------------------------------------------------";
|
||||
$lines[] = "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Przeciążenie dodawania usuwania tabeli
|
||||
*
|
||||
* @param string $script Zapytania
|
||||
*/
|
||||
protected function addDropStatements(&$script)
|
||||
{
|
||||
if (stPropelGeneratorController::isDropStatements())
|
||||
{
|
||||
parent::addDropStatements($script);
|
||||
}
|
||||
}
|
||||
|
||||
// protected static function getPropelConnection()
|
||||
// {
|
||||
// if (null === self::$con)
|
||||
// {
|
||||
// define('SF_ROOT_DIR', sfConfig::get('sf_root_dir'));
|
||||
|
||||
// define('SF_APP', 'backend');
|
||||
|
||||
// define('SF_ENVIRONMENT', 'prod');
|
||||
|
||||
// define('SF_DEBUG', false);
|
||||
|
||||
// require_once SF_ROOT_DIR.DIRECTORY_SEPARATOR.'apps'.DIRECTORY_SEPARATOR.SF_APP.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php';
|
||||
// $databaseManager = new sfDatabaseManager();
|
||||
// $databaseManager->initialize();
|
||||
|
||||
// self::$con = Propel::getConnection();
|
||||
// }
|
||||
|
||||
// return self::$con;
|
||||
// }
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user