Exemple #1
0
 /**
  * Return last log file name
  *
  * @return string
  */
 public function getLastLogFile()
 {
     $result = null;
     $filter = new \Includes\Utils\FileFilter(LC_DIR_LOG, '/\\/upgrade\\.log\\.\\d{4}-\\d{2}-\\d{2}\\.php$/', \RecursiveIteratorIterator::CHILD_FIRST);
     $paths = array();
     foreach ($filter->getIterator() as $file) {
         $paths[] = $file->getRealPath();
     }
     if ($paths) {
         arsort($paths);
         $result = reset($paths);
     }
     return $result;
 }
Exemple #2
0
 /**
  * Get structures to save when module is disabled
  *
  * @param string $author Module author
  * @param string $name   Module name
  *
  * @return array
  */
 public static function getModuleProtectedStructures($author, $name)
 {
     $tables = array();
     $columns = array();
     $path = static::getAbsoluteDir($author, $name) . 'Model';
     if (\Includes\Utils\FileManager::isExists($path)) {
         $filter = new \Includes\Utils\FileFilter($path, '/.*\\.php$/Si');
         foreach ($filter->getIterator() as $path => $data) {
             // DO NOT call "getInterfaces()" after the "getFullClassName()"
             // DO NOT use reflection to get interfaces
             $interfaces = \Includes\Decorator\Utils\Tokenizer::getInterfaces($path);
             $class = \Includes\Decorator\Utils\Tokenizer::getFullClassName($path);
             // Do 'autoload' checking first since the class_exists tries to use autoloader
             // but fails into "cannot include file" warning when model class is not set to use (LC_Dependencies issue)
             if (\Includes\Autoloader::checkAutoload($class) && class_exists($class)) {
                 // $reflectionClass = new \ReflectionClass($class);
                 if ($class && is_subclass_of($class, '\\XLite\\Model\\AEntity')) {
                     $class = ltrim($class, '\\');
                     $len = strlen(\Includes\Utils\Database::getTablesPrefix());
                     // DO NOT remove leading backslash in interface name
                     if (in_array('\\XLite\\Base\\IDecorator', $interfaces)) {
                         $parent = \Includes\Decorator\Utils\Tokenizer::getParentClassName($path);
                         $parent = ltrim($parent, '\\');
                         $metadata = \XLite\Core\Database::getEM()->getClassMetadata($parent);
                         $table = substr($metadata->getTableName(), $len);
                         $tool = new \Doctrine\ORM\Tools\SchemaTool(\XLite\Core\Database::getEM());
                         $schema = $tool->getCreateSchemaSql(array($metadata));
                         foreach ((array) $metadata->reflFields as $field => $reflection) {
                             $pattern = '/(?:, |\\()(' . $field . ' .+)(?:, [A-Za-z]|\\) ENGINE)/USsi';
                             if ($reflection->class === $class && !empty($metadata->fieldMappings[$field]) && preg_match($pattern, $schema[0], $matches)) {
                                 $columns[$table][$field] = $matches[1];
                             }
                         }
                         foreach ($metadata->associationMappings as $mapping) {
                             if ($metadata->reflFields[$mapping['fieldName']]->class === $class) {
                                 if (isset($mapping['joinTable']) && $mapping['joinTable']) {
                                     $tables[] = substr($mapping['joinTable']['name'], $len);
                                 } elseif (isset($mapping['joinColumns']) && $mapping['joinColumns']) {
                                     foreach ($mapping['joinColumns'] as $col) {
                                         $pattern = '/(?:, |\\()(' . $col['name'] . ' .+)(?:, [A-Za-z]|\\) ENGINE)/USsi';
                                         if (preg_match($pattern, $schema[0], $matches)) {
                                             $columns[$table][$col['name']] = $matches[1];
                                         }
                                     }
                                 }
                             }
                         }
                     } elseif (\XLite\Core\Database::getRepo($class)->canDisableTable()) {
                         $tables[] = substr(\XLite\Core\Database::getEM()->getClassMetadata($class)->getTableName(), $len);
                         $metadata = \XLite\Core\Database::getEM()->getClassMetadata($class);
                         foreach ($metadata->associationMappings as $mapping) {
                             if (isset($mapping['joinTable']) && $mapping['joinTable']) {
                                 $tables[] = substr($mapping['joinTable']['name'], $len);
                             }
                         }
                     }
                 }
             }
         }
     }
     return array('tables' => $tables, 'columns' => $columns);
 }
Exemple #3
0
 /**
  * Copy the whole directory tree
  *
  * @param string $dirFrom Catalog from which files will be copied
  * @param string $dirTo   Catalog to which files will be copied
  *
  * @return void
  */
 public static function copyRecursive($dirFrom, $dirTo)
 {
     if (static::isDir($dirFrom)) {
         $dirFrom = static::getCanonicalDir($dirFrom);
         $dirTo = static::getCanonicalDir($dirTo, false);
         $filter = new \Includes\Utils\FileFilter($dirFrom, null, \RecursiveIteratorIterator::CHILD_FIRST);
         foreach ($filter->getIterator() as $file) {
             $pathFrom = $file->getRealPath();
             $pathTo = $dirTo . static::getRelativePath($pathFrom, $dirFrom);
             if ($file->isDir()) {
                 static::mkdirRecursive($pathTo);
             } else {
                 static::copy($pathFrom, $pathTo);
             }
         }
     }
 }