/** * 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); }