Beispiel #1
0
 /**
  * Clean aggregation cache directory
  *
  * @return void
  */
 public function doActionCleanAggregationCache()
 {
     \Includes\Utils\FileManager::unlinkRecursive(LC_DIR_CACHE_RESOURCES);
     \Less_Cache::SetCacheDir(LC_DIR_DATACACHE);
     \Less_Cache::CleanCache();
     \XLite\Core\TopMessage::addInfo('Aggregation cache has been cleaned');
 }
Beispiel #2
0
 public function testGetPublicTitle()
 {
     \Includes\Utils\FileManager::unlinkRecursive(LC_DIR_FILES . 'attachments');
     $attach = $this->getTestAttachment();
     $this->assertEquals('max_ava.png', $attach->getPublicTitle(), 'check default title');
     $this->assertEquals('', $attach->getTitle(), 'check empty title');
     $attach->setTitle('test');
     $this->assertEquals('test', $attach->getPublicTitle(), 'check normal title');
 }
Beispiel #3
0
 /**
  * Execute certain hook handler
  *
  * @return void
  */
 public function executeHookHandler()
 {
     // Remove old capsular directories
     if (\Includes\Decorator\Utils\CacheManager::isCapsular()) {
         $currentKey = \Includes\Decorator\Utils\CacheManager::getKey();
         foreach (\Includes\Decorator\Utils\CacheManager::getCacheDirs(true) as $dir) {
             $list = glob(rtrim($dir, LC_DS) . '.*');
             if ($list) {
                 foreach ($list as $subdir) {
                     list($main, $key) = explode('.', $subdir, 2);
                     if ($key && $key != $currentKey) {
                         \Includes\Utils\FileManager::unlinkRecursive($subdir);
                     }
                 }
             }
         }
     }
     \Includes\Decorator\Utils\CacheManager::cleanupCache();
     // Load classes from "classes" (do not use cache)
     \Includes\Autoloader::switchLcAutoloadDir();
     \Includes\Decorator\Plugin\Doctrine\Plugin\QuickData\Main::initializeCounter();
 }
Beispiel #4
0
 /**
  * Clean aggregation cache directory
  *
  * @return void
  */
 public function doActionCleanAggregationCache()
 {
     \Includes\Utils\FileManager::unlinkRecursive(LC_DIR_CACHE_RESOURCES);
     \XLite\Core\TopMessage::addInfo('Aggregation cache has been cleaned');
     $this->setReturnURL($this->buildURL($this->get('target'), '', array('page' => 'Performance')));
 }
Beispiel #5
0
 /**
  * Uninstall module
  *
  * @param \XLite\Model\Module $module    Module object
  * @param array               &$messages Messages list
  *
  * @return boolean
  */
 public function uninstallModule(\XLite\Model\Module $module, &$messages)
 {
     $result = false;
     // Get module pack
     $pack = new \XLite\Core\Pack\Module($module);
     $dirs = $pack->getDirs();
     $nonWritableDirs = array();
     // Check module directories permissions
     foreach ($dirs as $dir) {
         if (\Includes\Utils\FileManager::isExists($dir) && !\Includes\Utils\FileManager::isDirWriteable($dir)) {
             $nonWritableDirs[] = \Includes\Utils\FileManager::getRelativePath($dir, LC_DIR_ROOT);
         }
     }
     $params = array('name' => sprintf('%s v%s (%s)', $module->getModuleName(), $module->getVersion(), $module->getAuthorName()));
     if (empty($nonWritableDirs)) {
         $yamlData = array();
         $yamlFiles = \Includes\Utils\ModulesManager::getModuleYAMLFiles($module->getAuthor(), $module->getName());
         foreach ($yamlFiles as $yamlFile) {
             $yamlData[] = \Includes\Utils\FileManager::read($yamlFile);
         }
         if (!$module->checkModuleMainClass()) {
             $classFile = LC_DIR_CLASSES . \Includes\Utils\Converter::getClassFile($module->getMainClass());
             if (\Includes\Utils\FileManager::isFileReadable($classFile)) {
                 require_once $classFile;
             }
         }
         // Call uninstall event method
         $r = $module->callModuleMethod('callUninstallEvent', 111);
         if (111 == $r) {
             \XLite\Logger::getInstance()->log($module->getActualName() . ': Method callUninstallEvent() was not called');
         }
         // Remove from FS
         foreach ($dirs as $dir) {
             \Includes\Utils\FileManager::unlinkRecursive($dir);
         }
         \Includes\Utils\ModulesManager::disableModule($module->getActualName());
         \Includes\Utils\ModulesManager::removeModuleFromDisabledStructure($module->getActualName());
         // Remove module from DB
         try {
             // Refresh module entity as it was changed by disableModule() method above
             $module = $this->find($module->getModuleID());
             $this->delete($module);
         } catch (\Exception $e) {
             $messages[] = $e->getMessage();
         }
         if ($module->getModuleID()) {
             $messages[] = \XLite\Core\Translation::getInstance()->translate('A DB error occured while uninstalling the module X', $params);
         } else {
             if (!empty($yamlData)) {
                 foreach ($yamlData as $yaml) {
                     \XLite\Core\Database::getInstance()->unloadFixturesFromYaml($yaml);
                 }
             }
             $messages[] = \XLite\Core\Translation::getInstance()->translate('The module X has been uninstalled successfully', $params);
             $result = true;
         }
     } else {
         $messages[] = \XLite\Core\Translation::getInstance()->translate('Unable to delete module X files: some dirs have no writable permissions: Y', $params + array('dirs' => implode(', ', $nonWritableDirs)));
     }
     return $result;
 }
Beispiel #6
0
 /**
  * Callback for a common operation for upgrade
  *
  * @param string  $path       File short path
  * @param boolean $isTestMode If in test mode
  *
  * @return void
  */
 protected function deleteFileCallback($path, $isTestMode)
 {
     if ($isTestMode) {
         if (!\Includes\Utils\FileManager::isDirWriteable($this->manageFile($path, 'getDir'))) {
             $this->addFileErrorMessage('File\'s directory is not writable', $path, false);
             $this->wrongPermissions[] = $this->manageFile($path, 'getDir');
         }
     } elseif ($this->manageFile($path, 'deleteFile')) {
         $this->addFileInfoMessage('File is deleted', $path, true);
         // Remove the parent directory if upgrade process removes all files in it
         $dir = dirname($path);
         if (\Includes\Utils\FileManager::isEmptyDir($dir)) {
             \Includes\Utils\FileManager::unlinkRecursive($dir);
             if (!\Includes\Utils\FileManager::isExists($dir)) {
                 $this->addFileInfoMessage('Directory is deleted', $dir, true);
             } else {
                 $this->addFileInfoMessage('Unable to delete directory', $dir, true);
             }
         }
     } else {
         $this->addFileErrorMessage('Unable to delete file', $path, true);
     }
 }
Beispiel #7
0
 /**
  * Uninstall module
  *
  * @return void
  */
 protected function doActionUninstall()
 {
     $module = $this->getModule();
     if ($module) {
         $pack = new \XLite\Core\Pack\Module($module);
         $dirs = $pack->getDirs();
         $nonWritableDirs = array();
         // Check permissions
         foreach ($dirs as $dir) {
             if (!\Includes\Utils\FileManager::isDirWriteable($dir)) {
                 $nonWritableDirs[] = \Includes\Utils\FileManager::getRelativePath($dir, LC_DIR_ROOT);
             }
         }
         $params = array('name' => $module->getActualName());
         if (empty($nonWritableDirs)) {
             $yaml = \Includes\Utils\FileManager::read(\Includes\Utils\ModulesManager::getModuleYAMLFile($module->getAuthor(), $module->getName()));
             // Remove from FS
             foreach ($dirs as $dir) {
                 \Includes\Utils\FileManager::unlinkRecursive($dir);
             }
             // Disable this and depended modules
             \Includes\Utils\ModulesManager::disableModule($module->getActualName());
             \Includes\Utils\ModulesManager::removeModuleFromDisabledStructure($module->getActualName());
             // Remove from DB
             \XLite\Core\Database::getRepo('\\XLite\\Model\\Module')->delete($module);
             if ($module->getModuleID()) {
                 $message = 'A DB error occured while uninstalling the module "{{name}}"';
                 $this->showError(__FUNCTION__, $message, $params);
             } else {
                 if (!empty($yaml)) {
                     \XLite\Core\Database::getInstance()->unloadFixturesFromYaml($yaml);
                 }
                 $message = 'The module "{{name}}" has been uninstalled successfully';
                 $this->showInfo(__FUNCTION__, $message, $params);
             }
             // To restore previous state
             \XLite\Core\Marketplace::getInstance()->saveAddonsList(0);
             // Flag to rebuild cache
             \XLite::setCleanUpCacheFlag(true);
         } else {
             $message = 'Unable to delete module "{{name}}" files: some dirs have no writable permissions: {{dirs}}';
             $this->showError(__FUNCTION__, $message, $params + array('dirs' => implode(', ', $nonWritableDirs)));
         }
     }
 }
Beispiel #8
0
 /**
  * Clean up the cache
  *
  * @return void
  */
 public static function cleanupCache()
 {
     foreach (static::$cacheDirs as $dir) {
         \Includes\Utils\FileManager::unlinkRecursive($dir);
         static::checkPermissions($dir);
     }
 }
Beispiel #9
0
 protected function setUp()
 {
     parent::setUp();
     \XLite\Core\Database::getEM()->clear();
     \Includes\Utils\FileManager::unlinkRecursive(LC_DIR_IMAGES . 'product');
 }
Beispiel #10
0
 /**
  * Delete all files
  *
  * @return void
  */
 public function deleteAllFiles()
 {
     $dir = \Includes\Utils\FileManager::getRealPath(LC_DIR_VAR . $this->getOptions()->dir);
     if (!\Includes\Utils\FileManager::isExists($dir)) {
         \Includes\Utils\FileManager::mkdir($dir);
     }
     $list = glob($dir . LC_DS . '*');
     if ($list) {
         foreach ($list as $path) {
             if (is_file($path)) {
                 \Includes\Utils\FileManager::deleteFile($path);
             } else {
                 \Includes\Utils\FileManager::unlinkRecursive($path);
             }
         }
     }
 }
Beispiel #11
0
 /**
  * Set repository path
  *
  * @param string  $path            Path to set
  * @param boolean $preventCheck    Flag OPTIONAL
  * @param boolean $preventDeletion Flag OPTIONAL
  *
  * @return void
  */
 public function setRepositoryPath($path, $preventCheck = false, $preventDeletion = false)
 {
     if (!empty($path) && !$preventCheck) {
         $path = \Includes\Utils\FileManager::getRealPath($path);
         if (empty($path) || !\Includes\Utils\FileManager::isReadable($path)) {
             $path = null;
         }
     }
     if (!$preventDeletion && !empty($this->repositoryPath) && $path !== $this->repositoryPath) {
         if ($this->isDownloaded()) {
             \Includes\Utils\FileManager::deleteFile($this->repositoryPath);
         } elseif ($this->isUnpacked()) {
             \Includes\Utils\FileManager::deleteFile($this->getCurrentVersionHashesFilePath());
             \Includes\Utils\FileManager::unlinkRecursive($this->repositoryPath);
         }
     }
     $this->repositoryPath = $path;
 }
Beispiel #12
0
 /**
  * Reset language driver
  *
  * @return void
  */
 public function reset()
 {
     \Includes\Utils\FileManager::unlinkRecursive(LC_DIR_LOCALE);
     $this->domains = array();
     $this->lastLanguage = null;
     $this->getRepo()->cleanCache();
 }
Beispiel #13
0
 /**
  * Save
  *
  * @param string $code Code
  *
  * @return void
  */
 protected function saveCode($code)
 {
     if ("\r\n" != PHP_EOL) {
         $code = str_replace("\r\n", PHP_EOL, $code);
     }
     $code = str_replace(chr(194) . chr(160), ' ', $code);
     $file = $this->getFileName();
     \Includes\Utils\FileManager::write($file, $code);
     if (\Includes\Utils\FileManager::isFileWriteable($file)) {
         \XLite\Core\TopMessage::addInfo('Your custom file is successfully saved');
         \Includes\Utils\FileManager::deleteFile(str_replace('custom', 'custom.min', $file));
         \XLite\Core\Database::getRepo('XLite\\Model\\Config')->createOption(array('name' => $this->getBackupName(), 'value' => $code, 'category' => 'XC\\ThemeTweaker'));
         \XLite\Core\Config::updateInstance();
         $config = \XLite\Core\Config::getInstance()->Performance;
         if ($config->aggregate_css || $config->aggregate_js) {
             \Includes\Utils\FileManager::unlinkRecursive(LC_DIR_CACHE_RESOURCES);
             \XLite\Core\TopMessage::addInfo('Aggregation cache has been cleaned');
         }
     } else {
         \XLite\Core\TopMessage::addError('The file {{file}} does not exist or is not writable.', array('file' => $file));
     }
 }
Beispiel #14
0
function copyRecursive($from, $to, $mode = 0666, $dir_mode = 0777)
{
    $orig_dir_mode = $dir_mode;
    if ($dir_mode == 0777) {
        $dir_mode = get_filesystem_permissions(0777);
    } elseif ($dir_mode == 0755) {
        $dir_mode = get_filesystem_permissions(0755);
    }
    $orig_mode = $mode;
    if ($mode == 0666) {
        $mode = get_filesystem_permissions(0666, $from);
    } elseif ($mode == 0644) {
        $mode = get_filesystem_permissions(0644, $from);
    }
    if (@is_file($from)) {
        @copy($from, $to);
        @umask(00);
        @chmod($to, $mode);
    } elseif (@is_dir($from)) {
        if (!@file_exists($to)) {
            @umask(00);
            $attempts = 5;
            while (!@mkdir($to, $dir_mode)) {
                \Includes\Utils\FileManager::unlinkRecursive($to);
                $attempts--;
                if ($attempts < 0) {
                    echo "Can't create directory {$to}: permission denied";
                    die;
                }
            }
        }
        if ($handle = @opendir($from)) {
            while (false !== ($file = @readdir($handle))) {
                if (!($file == "." || $file == "..")) {
                    copyRecursive($from . '/' . $file, $to . '/' . $file, $orig_mode, $orig_dir_mode);
                }
            }
            @closedir($handle);
        }
    } else {
        return 1;
    }
}
Beispiel #15
0
 /**
  * Creates the phpunit test suite
  *
  * @return PHPUnit_Framework_TestSuite
  * @access public
  * @see    ____func_see____
  * @since  1.0.0
  */
 public static function suite()
 {
     $suite = new PHPUnit_Framework_TestSuite(ROOT_TEST_SUITE_NAME);
     $deploy = null;
     $includes = false;
     $includeTests = array();
     $excludes = array();
     $ds = preg_quote(LC_DS, '/');
     if (defined('INCLUDE_ONLY_TESTS')) {
         $includes = array_map('trim', explode(',', INCLUDE_ONLY_TESTS));
         if (in_array('LOCAL_TESTS', $includes)) {
             $k = array_search('LOCAL_TESTS', $includes);
             unset($includes[$k]);
         }
         if (in_array('NOWEB', $includes)) {
             if (!defined('SELENIUM_DISABLED')) {
                 define('SELENIUM_DISABLED', true);
             }
             $k = array_search('NOWEB', $includes);
             unset($includes[$k]);
         }
         if (in_array('ONLYWEB', $includes)) {
             if (!defined('UNITS_DISABLED')) {
                 define('UNITS_DISABLED', true);
             }
             $k = array_search('ONLYWEB', $includes);
             unset($includes[$k]);
         }
         if (in_array('DEPLOY_DRUPAL', $includes)) {
             $deploy = 'Drupal';
         } elseif (in_array('DEPLOY_STANDALONE', $includes)) {
             $deploy = 'Standalone';
         }
         if (!is_null($deploy)) {
             if (!defined('UNITS_DISABLED')) {
                 define('UNITS_DISABLED', true);
             }
             $k = array_search('DEPLOY_' . strtoupper($deploy), $includes);
             if (!defined('DIR_TESTS')) {
                 define('DIR_TESTS', 'Deploy' . LC_DS . $deploy);
             }
             unset($includes[$k]);
         }
         if (in_array('W3C', $includes)) {
             if (!defined('W3C_VALIDATION')) {
                 define('W3C_VALIDATION', true);
             }
             $k = array_search('W3C', $includes);
             unset($includes[$k]);
         }
         foreach ($includes as $k => $v) {
             if ('-' == substr($v, 0, 1)) {
                 $excludes[] = substr($v, 1);
                 unset($includes[$k]);
             }
         }
         foreach ($includes as $k => $v) {
             $tmp = explode(':', $v, 2);
             $includes[$k] = $tmp[0];
             if (isset($tmp[1])) {
                 $includeTests[$tmp[0]] = $tmp[1];
             }
         }
     }
     if (isset($deploy) && !defined('DEPLOYMENT_TEST')) {
         define('DEPLOYMENT_TEST', true);
     }
     // Include abstract classes
     $classesDir = dirname(__FILE__);
     $pattern = '/^' . preg_quote($classesDir, '/') . '.*' . $ds . '(?:\\w*Abstract|A[A-Z][a-z]\\w*)\\.php$/Ss';
     $dirIterator = new RecursiveDirectoryIterator($classesDir . LC_DS);
     $iterator = new RecursiveIteratorIterator($dirIterator, RecursiveIteratorIterator::CHILD_FIRST);
     foreach ($iterator as $filePath => $fileObject) {
         if (preg_match($pattern, $filePath, $matches)) {
             require_once $filePath;
         }
     }
     // Include fake classes
     if (!defined('DEPLOYMENT_TEST')) {
         $classesDir = dirname(__FILE__) . LC_DS . 'FakeClass' . LC_DS;
         $pattern = '/^' . preg_quote($classesDir, '/') . '.+\\.php$/Ss';
         $dirIterator = new RecursiveDirectoryIterator($classesDir . LC_DS);
         $iterator = new RecursiveIteratorIterator($dirIterator, RecursiveIteratorIterator::CHILD_FIRST);
         foreach ($iterator as $filePath => $fileObject) {
             if (preg_match($pattern, $filePath, $matches)) {
                 require_once $filePath;
             }
         }
     }
     if (!isset($deploy) || !$deploy) {
         \Includes\Utils\FileManager::unlinkRecursive(__DIR__ . '/images');
         \Includes\Utils\FileManager::mkdirRecursive(__DIR__ . '/images');
         \Includes\Utils\FileManager::copyRecursive(LC_DIR_IMAGES, __DIR__ . '/images/');
         //xlite_make_sql_backup();
     }
     // Classes tests
     if (!defined('UNITS_DISABLED')) {
         $classesDir = dirname(__FILE__) . LC_DS . 'Classes' . LC_DS;
         $pattern = '/^' . preg_quote($classesDir, '/') . '(.*)\\.php$/';
         $dirIterator = new RecursiveDirectoryIterator($classesDir);
         $iterator = new RecursiveIteratorIterator($dirIterator, RecursiveIteratorIterator::CHILD_FIRST);
         $siterator = new XLite_Tests_SortedIterator($iterator);
         foreach ($siterator as $filePath) {
             if (preg_match($pattern, $filePath, $matches) && !empty($matches[1]) && !preg_match('/' . $ds . '(\\w+Abstract|A[A-Z]\\w+)\\.php$/Ss', $filePath) && !preg_match('/' . $ds . '(?:scripts|skins)' . $ds . '/Ss', $filePath)) {
                 $matched = str_replace(LC_DS, '/', $matches[1]);
                 if ((!$includes || static::isPatternInArray($matched, $includes)) && (!$excludes || !static::isPatternInArray($matched, $excludes))) {
                     $class = XLite_Tests_TestCase::CLASS_PREFIX . str_replace('/', '_', $matched);
                     require_once $filePath;
                     $suite->addTest(new PHPUnit_Framework_TestSuite(new ReflectionClass($class)));
                     // Limit test range by a specific test if it was specified in call. Example: ./phpunit-report.sh Model/Zone:create
                     if (isset($includeTests[$matched])) {
                         eval($class . '::$testsRange = array($includeTests[$matched]);');
                     }
                 }
             }
         }
     }
     // Web tests
     if (!defined('SELENIUM_DISABLED')) {
         if (!defined('DIR_TESTS')) {
             define('DIR_TESTS', 'Web');
         }
         $classesDir = dirname(__FILE__) . LC_DS . constant('DIR_TESTS') . LC_DS;
         $pattern = '/^' . preg_quote($classesDir, '/') . '(.*)\\.php$/';
         $dirIterator = new RecursiveDirectoryIterator($classesDir);
         $iterator = new RecursiveIteratorIterator($dirIterator, RecursiveIteratorIterator::CHILD_FIRST);
         $siterator = new XLite_Tests_SortedIterator($iterator);
         foreach ($siterator as $filePath) {
             if (preg_match($pattern, $filePath, $matches) && !empty($matches[1]) && !preg_match('/' . $ds . '(\\w+Abstract|A[A-Z]\\w+)\\.php/Ss', $filePath) && !preg_match('/' . $ds . '(?:scripts|skins)' . $ds . '/Ss', $filePath)) {
                 $matched = str_replace(LC_DS, '/', $matches[1]);
                 if ((!$includes || static::isPatternInArray($matched, $includes)) && (!$excludes || !static::isPatternInArray($matched, $excludes))) {
                     $classPrefix = !isset($deploy) ? XLite_Tests_SeleniumTestCase::CLASS_PREFIX : 'XLite_Deploy_' . $deploy . '_';
                     $class = $classPrefix . str_replace('/', '_', $matched);
                     require_once $filePath;
                     $seleniumSuite = new PHPUnit_Framework_TestSuite();
                     $seleniumSuite->addTestSuite($class);
                     $suite->addTest($seleniumSuite);
                     // Limit test range by a specific test if it was specified in call. Example: ./phpunit-report.sh Model/Zone:create
                     if (isset($includeTests[$matched])) {
                         eval($class . '::$testsRange = array($includeTests[$matched]);');
                     }
                 }
             }
         }
     }
     error_reporting(E_ALL);
     return $suite;
 }
Beispiel #16
0
 /**
  * testRenewStorage
  *
  * @return void
  * @see    ____func_see____
  * @since  1.0.12
  */
 public function testRenewStorage()
 {
     \Includes\Utils\FileManager::unlinkRecursive(LC_DIR_FILES . 'attachments');
     $storage = $this->getTestStorage();
     $size = $storage->getSize();
     $path = LC_DIR_FILES . 'attachments' . LC_DS . $storage->getPath();
     $this->assertTrue(file_exists($path), 'check exist');
     $s2 = $this->getTestStorage();
     $this->assertTrue($s2->loadFromLocalFile($path), 'check duplicate loading');
     \XLite\Core\Database::getEM()->flush();
     unlink($path);
     copy(__DIR__ . '/../vertical_dots.png', $path);
     $this->assertTrue($storage->renewStorage(), 'check renew storage status');
     $this->assertNotEquals($size, $storage->getSize(), 'check old file size');
     $this->assertEquals(filesize($path), $storage->getSize(), 'check file size');
     $this->assertEquals(filesize($path), $s2->getSize(), 'check file size #2');
 }
Beispiel #17
0
 /**
  * PHPUnit default function.
  * It's not recommended to redefine this method
  *
  * @return void
  * @access protected
  * @see    ____func_see____
  * @since  1.0.0
  */
 protected function tearDown()
 {
     \Includes\Utils\FileManager::unlinkRecursive(LC_DIR_MODULES . 'CDev' . LC_DS . 'TestSkin');
     \Includes\Utils\FileManager::unlinkRecursive(LC_DIR_CACHE_CLASSES . 'XLite' . LC_DS . 'Module' . LC_DS . 'CDev' . LC_DS . 'TestSkin');
     \Includes\Utils\FileManager::unlinkRecursive(LC_DIR_SKINS . 'test');
     $skin = \XLite\Core\Database::getRepo('XLite\\Model\\Module')->findOneBy(array('name' => 'TestSkin', 'author' => 'CDev'));
     if ($skin) {
         \XLite\Core\Database::getEM()->remove($skin);
         \XLite\Core\Database::getEM()->flush();
     }
     \XLite\Core\Database::getCacheDriver()->deleteAll();
     \Includes\Utils\FileManager::unlinkRecursive(LC_DIR_COMPILE . 'skins');
     parent::tearDown();
 }
Beispiel #18
0
 /**
  * Make backup
  *
  * @return void
  * @see    ____func_see____
  * @since  1.0.11
  */
 protected function doMakeBackup($path)
 {
     ob_start();
     xlite_make_sql_backup($path);
     ob_end_clean();
     \Includes\Utils\FileManager::unlinkRecursive(LC_DIR . '/../.dev/tests/images');
     \Includes\Utils\FileManager::mkdirRecursive(LC_DIR . '/../.dev/tests/images');
     \Includes\Utils\FileManager::copyRecursive(LC_DIR_IMAGES, LC_DIR . '/../.dev/tests/images/');
 }
Beispiel #19
0
function xlite_make_sql_backup($path = null)
{
    // DB backup
    echo PHP_EOL . 'DB backup ... ';
    \Includes\Utils\FileManager::unlinkRecursive(__DIR__ . '/images');
    \Includes\Utils\FileManager::mkdirRecursive(__DIR__ . '/images');
    \Includes\Utils\FileManager::mkdirRecursive(__DIR__ . '/images/product');
    \Includes\Utils\FileManager::mkdirRecursive(__DIR__ . '/images/category');
    \Includes\Utils\FileManager::copyRecursive(LC_DIR_IMAGES, __DIR__ . '/images');
    $result = true;
    if (!isset($path)) {
        $path = dirname(__FILE__) . LC_DS . 'dump.sql';
    }
    if (file_exists(dirname($path))) {
        if (file_exists($path)) {
            unlink($path);
        }
        $config = \XLite::getInstance()->getOptions('database_details');
        $cmd = defined('TEST_MYSQLDUMP_BIN') ? TEST_MYSQLDUMP_BIN : 'mysqldump';
        $cmd .= ' --opt -h' . $config['hostspec'];
        if ($config['port']) {
            $cmd .= ' -P' . $config['port'];
        }
        $cmd .= ' -u' . $config['username'] . ('' == $config['password'] ? '' : ' -p' . $config['password']);
        if ($config['socket']) {
            $cmd .= ' -S' . $config['socket'];
        }
        $cmd .= ' ' . $config['database'];
        exec('echo "SET autocommit=0;
        SET unique_checks=0;
        SET foreign_key_checks=0;" > ' . $path . '
        ' . $cmd . ' >> ' . $path . '
        echo "COMMIT;" >> ' . $path);
        echo 'done' . PHP_EOL;
        sleep(1);
    } else {
        $result = false;
    }
    if (!$result) {
        echo 'ignored' . PHP_EOL;
    }
    return $result;
}