Esempio n. 1
0
 /**
  * Get valid file system storage root
  *
  * @return string
  */
 protected function getStoreFileSystemRoot()
 {
     $shipments = $this->getLink()->getManifest()->getShipments();
     $path = parent::getStoreFileSystemRoot() . $shipments[0]->getParcel()->getOrder()->getOrderId() . LC_DS;
     \Includes\Utils\FileManager::mkdirRecursive($path);
     return $path;
 }
Esempio n. 2
0
File: Main.php Progetto: kingsj/core
 /**
  * Execute certain hook handle
  *
  * @return void
  */
 public function executeHookHandler()
 {
     if (!$this->areProxiesExist()) {
         // Create the proxies folder
         \Includes\Utils\FileManager::mkdirRecursive(LC_DIR_CACHE_PROXY);
         // Create model proxy classes (second step of cache generation)
         \Includes\Decorator\Plugin\Doctrine\Utils\EntityManager::generateProxies();
     }
 }
Esempio n. 3
0
 /**
  * Constructor
  * Creates directory for locks if needed
  */
 public function __construct()
 {
     if (!\Includes\Utils\FileManager::isExists(rtrim(static::LOCK_DIR, LC_DS))) {
         \Includes\Utils\FileManager::mkdirRecursive(rtrim(static::LOCK_DIR, LC_DS));
     }
     if (!\Includes\Utils\FileManager::isReadable(static::LOCK_DIR) || !\Includes\Utils\FileManager::isWriteable(static::LOCK_DIR)) {
         \XLite\Logger::getInstance()->log('Cannot create lock for keys', LOG_DEBUG);
     }
     parent::__construct();
 }
Esempio n. 4
0
 /**
  * Set cache path
  *
  * @param string $path Path
  *
  * @return void
  */
 public function setPath($path)
 {
     if (is_string($path)) {
         if (!file_exists($path)) {
             \Includes\Utils\FileManager::mkdirRecursive($path);
         }
         if (file_exists($path) && is_dir($path)) {
             $this->path = $path;
         }
     }
 }
Esempio n. 5
0
 /**
  * Update custom images
  *
  * @return void
  */
 protected function updateCustomImages()
 {
     $dir = \XLite\Module\XC\ThemeTweaker\Main::getThemeDir() . 'images' . LC_DS;
     if ($_FILES && $_FILES['new_images'] && $_FILES['new_images']['name']) {
         if (!\Includes\Utils\FileManager::isExists($dir)) {
             \Includes\Utils\FileManager::mkdirRecursive($dir);
         }
         if (\Includes\Utils\FileManager::isDirWriteable($dir)) {
             foreach ($_FILES['new_images']['name'] as $i => $data) {
                 \Includes\Utils\FileManager::moveUploadedFileByMultiple('new_images', $i, $dir);
             }
         } else {
             \XLite\Core\TopMessage::addError('The directory {{dir}} does not exist or is not writable.', array('dir' => $dir));
         }
     }
     $delete = \XLite\Core\Request::getInstance()->delete;
     if ($delete && is_array($delete)) {
         foreach ($delete as $file => $del) {
             if ($del) {
                 \Includes\Utils\FileManager::deleteFile($dir . $file);
             }
         }
     }
 }
Esempio n. 6
0
define('LC_CUSTOMER_AREA_SKIN', LC_DIR_SKINS . 'default' . LC_DS . 'en' . LC_DS);
define('LC_ADMIN_AREA_SKIN', LC_DIR_SKINS . 'admin' . LC_DS . 'en' . LC_DS);
// Images subsystem settings
define('LC_IMAGES_URL', 'images');
define('LC_IMAGES_CACHE_URL', LC_VAR_URL . '/images');
// Files
define('LC_FILES_URL', 'files');
define('LC_HORN', 'Ly93d3cueC1jYXJ0LmNvbS9pbWc');
// OS
define('LC_OS_NAME', preg_replace('/^([^ ]+)/', '\\1', PHP_OS));
define('LC_OS_CODE', strtolower(substr(LC_OS_NAME, 0, 3)));
define('LC_OS_IS_WIN', LC_OS_CODE === 'win');
// Session type
define('LC_SESSION_TYPE', 'Sql');
set_include_path(get_include_path() . PATH_SEPARATOR . LC_DIR_LIB);
// Some common functions
require_once LC_DIR_ROOT . 'Includes' . LC_DS . 'functions.php';
// Common error reporting settings
$path = LC_DIR_LOG . 'php_errors.log.' . date('Y-m-d') . '.php';
if (!file_exists(dirname($path)) && is_writable(LC_DIR_VAR)) {
    \Includes\Utils\FileManager::mkdirRecursive(dirname($path));
}
if ((!file_exists($path) || 16 > filesize($path)) && is_writable(dirname($path))) {
    file_put_contents($path, '<' . '?php die(1); ?' . '>' . "\n");
    ini_set('error_log', $path);
}
ini_set('log_errors', true);
ini_set("auto_detect_line_endings", true);
unset($path);
// Set default memory limit
func_set_memory_limit('128M');
Esempio n. 7
0
 /**
  * Check security header for specified file
  *
  * @param string $path File path
  *
  * @return void
  */
 protected function checkLogSecurityHeader($path)
 {
     if (!file_exists(dirname($path))) {
         \Includes\Utils\FileManager::mkdirRecursive(dirname($path));
     }
     if (!file_exists($path) || $this->securityHeader > filesize($path)) {
         file_put_contents($path, $this->securityHeader . "\n");
     }
 }
Esempio n. 8
0
 /**
  * Import action
  *
  * @return void
  */
 protected function doActionImport()
 {
     foreach (\XLite\Logic\Import\Importer::getImportOptionsList() as $key) {
         \XLite\Core\Database::getRepo('XLite\\Model\\Config')->createOption(array('category' => 'Import', 'name' => $key, 'value' => isset(\XLite\Core\Request::getInstance()->options[$key]) ? \XLite\Core\Request::getInstance()->options[$key] : false));
     }
     \XLite\Core\Config::updateInstance();
     $dirTo = LC_DIR_VAR . \XLite\Logic\Import\Importer::getImportDir();
     if (!\Includes\Utils\FileManager::isExists($dirTo)) {
         \Includes\Utils\FileManager::mkdirRecursive($dirTo);
     }
     $filesToImport = array();
     if ($_FILES && isset($_FILES['files']) && $_FILES['files']['name'] && $_FILES['files']['name'][0] && \Includes\Utils\FileManager::isDirWriteable($dirTo)) {
         $list = glob($dirTo . LC_DS . '*');
         if ($list) {
             foreach ($list as $path) {
                 if (is_file($path)) {
                     \Includes\Utils\FileManager::deleteFile($path);
                 }
             }
         }
         $files = $_FILES['files'];
         foreach ($files['name'] as $key => $name) {
             $path = null;
             if ($name && UPLOAD_ERR_OK === $files['error'][$key]) {
                 $path = \Includes\Utils\FileManager::getUniquePath($dirTo, $name ?: $files['name'][$key]);
                 if (move_uploaded_file($files['tmp_name'][$key], $path)) {
                     if (\XLite\Core\Archive::getInstance()->isArchive($path) || 'csv' == substr(strrchr($path, '.'), 1)) {
                         $filesToImport[] = $path;
                     } else {
                         \XLite\Core\TopMessage::addError('The "{{file}}" is not CSV or archive', array('file' => $name));
                         \Includes\Utils\FileManager::deleteFile($path);
                     }
                 } else {
                     $path = null;
                 }
             }
             if (!$path) {
                 \XLite\Core\TopMessage::addError('The "{{file}}" file was not uploaded', array('file' => $name));
             }
         }
     }
     if ($filesToImport) {
         \XLite\Logic\Import\Importer::run(\XLite\Logic\Import\Importer::assembleImportOptions() + array('files' => $filesToImport));
     }
 }
Esempio n. 9
0
// For module XC\MultiVendor
$auth = \XLite\Core\Auth::getInstance();
if (!$auth->isAdmin()) {
    die('forbidden');
} elseif (method_exists($auth, 'isVendor') && $auth->isVendor()) {
    $vendor = 'vendor_' . $auth->getProfile()->getProfileId();
    $upload_dir = 'filemanager' . LC_DS . 'uploads' . LC_DS . $vendor;
    // path from the base_url to the uploads folder
    $thumbs_dir = 'filemanager' . LC_DS . 'thumbs' . LC_DS . $vendor;
    // path from the base_url to thumbs folder
}
if (!is_dir($root . $upload_dir)) {
    \Includes\Utils\FileManager::mkdirRecursive($root . $upload_dir);
}
if (!is_dir($root . $thumbs_dir)) {
    \Includes\Utils\FileManager::mkdirRecursive($root . $thumbs_dir);
}
$MaxSizeUpload = 1000;
//Mb
//**********************
//Image config
//**********************
//set max width pixel or the max height pixel for all images
//If you set dimension limit, automatically the images that exceed this limit are convert to limit, instead
//if the images are lower the dimension is maintained
//if you don't have limit set both to 0
$image_max_width = 0;
$image_max_height = 0;
//Automatic resizing //
//If you set true $image_resizing the script convert all images uploaded to image_width x image_height resolution
//If you set width or height to 0 the script calcolate automatically the other size
Esempio n. 10
0
 /**
  * Additional preparations for images.
  * Upload them into specific directory
  *
  * @param string $optionValue Option value
  * @param string $imageType   Image type
  *
  * @return string
  */
 protected function prepareImageData($optionValue, $imageType)
 {
     $dir = static::getLogoFaviconDir();
     if ($_FILES && $_FILES[$imageType] && $_FILES[$imageType]['name']) {
         $path = null;
         $realName = preg_replace('/([^a-zA-Z0-9_\\-\\.]+)/', '_', $_FILES[$imageType]['name']);
         if ($this->isImage($_FILES[$imageType]['tmp_name'], $realName)) {
             if (!\Includes\Utils\FileManager::isDir($dir)) {
                 \Includes\Utils\FileManager::mkdirRecursive($dir);
             }
             if (\Includes\Utils\FileManager::isDir($dir)) {
                 // Remove file with same name as uploaded file in the destination directory
                 \Includes\Utils\FileManager::deleteFile($dir . LC_DS . ('favicon' === $imageType ? static::FAVICON : $realName));
                 // Move uploaded file to destination directory
                 $path = \Includes\Utils\FileManager::moveUploadedFile($imageType, $dir, 'favicon' === $imageType ? static::FAVICON : $realName);
                 if ($path) {
                     if ($optionValue && 'favicon' !== $imageType && basename($optionValue) != $realName) {
                         // Remove old image file
                         \Includes\Utils\FileManager::deleteFile($dir . basename($optionValue));
                     }
                     $optionValue = static::getLogoFaviconSubDir() . basename($path);
                 }
             }
             if (!isset($path)) {
                 $this->logoFaviconValidation = false;
                 \XLite\Core\TopMessage::addError('The "{{file}}" file was not uploaded', array('file' => $realName));
             }
         } else {
             $this->logoFaviconValidation = false;
             \XLite\Core\TopMessage::addError('The "{{file}}" file is not allowed image and was not uploaded. Allowed images are: {{extensions}}', array('file' => $realName, 'extensions' => implode(', ', $this->getImageExtensions())));
         }
     } elseif (\XLite\Core\Request::getInstance()->useDefaultImage[$imageType]) {
         if ($optionValue) {
             \Includes\Utils\FileManager::deleteFile($dir . basename($optionValue));
         }
         $optionValue = '';
     }
     return $optionValue;
 }
Esempio n. 11
0
function func_unlock($lockname)
{
    global $_lock_hash;
    $options = \Includes\Utils\ConfigParser::getOptions();
    if (empty($lockname) || empty($_lock_hash[$lockname])) {
        return false;
    }
    $lockDir = $options["decorator_details"]["lockDir"];
    // remove last '/'
    if ($lockDir[strlen($lockDir) - 1] == '/') {
        $lockDir = substr($lockDir, 0, strlen($lockDir) - 1);
    }
    if (!is_dir($lockDir)) {
        \Includes\Utils\FileManager::mkdirRecursive($lockDir);
    }
    $fname = $lockDir . "/" . $lockname . ".lock";
    if (!file_exists($fname)) {
        return false;
    }
    $fp = fopen($fname, "r");
    if (!$fp) {
        return false;
    }
    $tmp = fread($fp, 43);
    fclose($fp);
    $file_id = substr($tmp, 0, 32);
    $file_time = (int) substr($tmp, 32);
    if ($file_id == $_lock_hash[$lockname]) {
        @unlink($fname);
    }
    unset($_lock_hash[$lockname]);
    return true;
}
Esempio n. 12
0
 /**
  * Check directory permissions and try to correct them
  *
  * @param string $dir Path to check
  *
  * @return void
  */
 protected static function checkPermissions($dir)
 {
     \Includes\Utils\FileManager::mkdirRecursive($dir);
     if (!\Includes\Utils\FileManager::isDirWriteable($dir)) {
         @\Includes\Utils\FileManager::chmod($dir, static::getDirDefaultPermissions($dir));
         if (!\Includes\Utils\FileManager::isDirWriteable($dir)) {
             static::fireDirPermissionsError($dir);
         }
     }
 }
Esempio n. 13
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/');
 }
Esempio n. 14
0
File: core.php Progetto: kingsj/core
/**
 * Safe write to file
 * 
 * @param string $path Path
 * @param string $data File content
 *  
 * @return void
 * @see    ____func_see____
 * @since  1.0.18
 */
function macro_file_put_contents($path, $data)
{
    if (!\Includes\Utils\FileManager::mkdirRecursive(dirname($path))) {
        macro_error('Directory \'' . $path . '\' write-protected!');
    }
    if (!@file_put_contents($path, $data)) {
        macro_error('File \'' . $path . '\' write-protected!');
    }
}
Esempio n. 15
0
 /**
  * isDirExists
  *
  * @return boolean
  */
 protected function isDirExists()
 {
     $result = is_dir(LC_DIR_BACKUP);
     if (!$result) {
         \Includes\Utils\FileManager::mkdirRecursive(LC_DIR_BACKUP);
     }
     $result = is_dir(LC_DIR_BACKUP) && is_writable(LC_DIR_BACKUP);
     return $result;
 }
Esempio n. 16
0
 /**
  * Get file iterator
  *
  * @return \RecursiveIteratorIterator
  */
 protected function getFileIterator()
 {
     $dir = LC_DIR_VAR . $this->getOptions()->dir . LC_DS;
     if (!\Includes\Utils\FileManager::isExists($dir)) {
         \Includes\Utils\FileManager::mkdirRecursive($dir);
     }
     $dirIterator = new \RecursiveDirectoryIterator($dir, \FilesystemIterator::KEY_AS_PATHNAME | \FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::SKIP_DOTS);
     return new \RecursiveIteratorIterator($dirIterator, \RecursiveIteratorIterator::SELF_FIRST);
 }
Esempio n. 17
0
 /**
  * Create index file (.mo file) with msgfmt console script
  *
  * @param string $path Output path
  * @param string $code Language code
  *
  * @return boolean
  */
 protected function createIndexFileBin($path, $code)
 {
     $list = $this->getRepo()->findLabelsByCode($code);
     $list[self::SERVICE_LBL] = self::SERVICE_VALUE;
     $result = false;
     if (!file_exists(LC_DIR_TMP)) {
         \Includes\Utils\FileManager::mkdirRecursive(LC_DIR_TMP);
     }
     $poPath = LC_DIR_TMP . 'translate.' . $code . '.po';
     $fp = @fopen($poPath, 'wb');
     if ($fp) {
         fwrite($fp, 'msgid ""' . "\n" . 'msgstr ""' . "\n" . '"Project-Id-Version: ' . \XLite::getInstance()->getVersion() . '\\n"' . "\n" . '"PO-Revision-Date: ' . date('Y-m-d H:iO') . '\\n"' . "\n" . '"Last-Translator: local\\n"' . "\n" . '"Language-Team: local\\n"' . "\n" . '"MIME-Version: 1.0\\n"' . "\n" . '"Content-Type: text/plain; charset=UTF-8\\n"' . "\n" . '"Content-Transfer-Encoding: 8bit\\n"' . "\n" . "\n");
         foreach ($list as $k => $v) {
             fwrite($fp, 'msgid "' . addcslashes(str_replace("\n", '\\n', $k), '"\\') . '"' . "\n" . 'msgstr "' . addcslashes(str_replace("\n", '\\n', $v), '"\\') . '"' . "\n\n");
         }
         fclose($fp);
         $exec = $this->getMsgFmtExecutable();
         if ($exec) {
             $exec .= ' ' . $poPath . ' -o ' . $path;
             exec($exec);
             unlink($poPath);
         }
         $result = file_exists($path);
     }
     return $result;
 }
Esempio n. 18
0
 /**
  * isDirExists
  *
  * @return boolean
  */
 public function isDirExists()
 {
     if (!is_dir(LC_DIR_BACKUP)) {
         \Includes\Utils\FileManager::mkdirRecursive(LC_DIR_BACKUP);
     }
     return \Includes\Utils\FileManager::isDirWriteable(LC_DIR_BACKUP);
 }
Esempio n. 19
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;
 }
Esempio n. 20
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;
}
Esempio n. 21
0
 /**
  * Return resource structure from the file cache
  *
  * @param string $type                   File type of resource (js/css)
  * @param array  $resources              Resources for caching
  * @param array  $paramsForCache         Parameters of file cache (directory structure path to file)
  * @param string $prepareCacheFileMethod Method of $this object to read one resource entity and do some inner work if it is necessary
  *
  * @return array
  */
 protected function getResourceFromCache($type, array $resources, array $paramsForCache, $prepareCacheFileMethod)
 {
     $pathToCacheDir = static::getResourceCacheDir($paramsForCache);
     \Includes\Utils\FileManager::mkdirRecursive($pathToCacheDir);
     $file = hash('sha256', serialize($resources)) . '.' . $type;
     $filePath = $pathToCacheDir . $file;
     if (!\Includes\Utils\FileManager::isFile($filePath)) {
         foreach ($resources as $resource) {
             \Includes\Utils\FileManager::write($filePath, $this->{$prepareCacheFileMethod}($resource['file']), FILE_APPEND);
         }
     }
     return array('file' => $filePath, 'url' => \XLite::getInstance()->getShopURL(str_replace(LC_DS, '/', substr($filePath, strlen(LC_DIR_ROOT))), \XLite\Core\Request::getInstance()->isHTTPS()));
 }
Esempio n. 22
0
 /**
  * Get valid file system storage root
  *
  * @return string
  */
 protected function getValidFileSystemRoot()
 {
     $path = $this->getFileSystemRoot();
     \Includes\Utils\FileManager::mkdirRecursive($path);
     return $path;
 }
Esempio n. 23
0
 /**
  * Get valid file system storage root
  *
  * @return string
  */
 protected function getStoreFileSystemRoot()
 {
     $path = parent::getStoreFileSystemRoot() . $this->getAttachment()->getProduct()->getProductId() . LC_DS;
     \Includes\Utils\FileManager::mkdirRecursive($path);
     return $path;
 }
Esempio n. 24
0
 /**
  * Export images
  *
  * @param \XLite\Model\Product $product Product
  *
  * @return string
  */
 protected function exportImages(\XLite\Model\Product $product)
 {
     $list = array();
     if (0 < count($product->getImages())) {
         $path = LC_DIR_TMP . $this->exportId . LC_DS . 'images' . LC_DS . 'product' . LC_DS . $product->getProductId();
         \Includes\Utils\FileManager::mkdirRecursive($path);
         $path .= LC_DS;
         foreach ($product->getImages() as $image) {
             if ($image->isURL()) {
                 $list[] = $image->getFrontURL();
             } else {
                 $name = $image->getPath() ?: $image->getId() . '.' . $image->getExtension();
                 $subpath = $path . $name;
                 if (@file_put_contents($subpath, $image->getBody())) {
                     $list[] = $subpath;
                 }
             }
         }
     }
     return implode(';', $list);
 }
Esempio n. 25
0
 /**
  * Get browscap client 
  * 
  * @return \phpbrowscap\Browscap
  */
 protected function getBrowscapClient()
 {
     require_once LC_DIR_LIB . 'Browscap.php';
     $cacheDir = LC_DIR_DATA . 'browscap';
     if (!file_exists($cacheDir)) {
         \Includes\Utils\FileManager::mkdirRecursive($cacheDir);
         \Includes\Utils\FileManager::copy($this->getBrowsCapPath(), $cacheDir . LC_DS . 'browscap.ini');
     }
     return new \phpbrowscap\Browscap($cacheDir);
 }
Esempio n. 26
0
 /**
  * Create a main less file for the provided less files collection
  *
  * @param array $lessFiles LESS files structures array
  *
  * @return string LESS file name
  */
 protected function makeLESSResourcePath($lessFiles)
 {
     $filePath = $this->getCacheDir('screen') . $this->getUniqueName($lessFiles) . '.less';
     if (!is_file($filePath)) {
         $content = '';
         foreach ($lessFiles as $resource) {
             $resourcePath = \Includes\Utils\FileManager::makeRelativePath($this->getCacheDir('screen'), $resource['file']);
             $content .= "\r\n" . '@import "' . str_replace('/', LC_DS, $resourcePath) . '";' . "\r\n";
         }
         \Includes\Utils\FileManager::mkdirRecursive(dirname($filePath));
         \Includes\Utils\FileManager::write($filePath, $content);
     }
     return $filePath;
 }