public static function websiteCreated($params)
 {
     global $REX;
     $log = $params['subject']['log_object'];
     $sourceWebsiteId = $REX['ADDON']['siteclone']['settings']['source_webiste_id'];
     $sourceTablePrefix = $REX['WEBSITE_MANAGER']->getWebsite($sourceWebsiteId)->getTablePrefix();
     $newWebsiteId = $params['subject']['website_id'];
     $newTablePrefix = $params['subject']['table_prefix'];
     $sql = new rex_sql();
     //$sql->debugsql = true;
     // copy structure table data
     if ($REX['ADDON']['siteclone']['settings']['clone_structure']) {
         rex_website_manager_utils::logQuery($log, $sql, 'INSERT INTO `' . $newTablePrefix . 'article` SELECT * FROM ' . $sourceTablePrefix . 'article');
     }
     // copy slices table data
     if ($REX['ADDON']['siteclone']['settings']['clone_slices']) {
         rex_website_manager_utils::logQuery($log, $sql, 'INSERT INTO `' . $newTablePrefix . 'article_slice` SELECT * FROM ' . $sourceTablePrefix . 'article_slice');
     }
     // copy media table data
     if ($REX['ADDON']['siteclone']['settings']['clone_media']) {
         rex_website_manager_utils::logQuery($log, $sql, 'INSERT INTO `' . $newTablePrefix . 'file_category` SELECT * FROM ' . $sourceTablePrefix . 'file_category');
         rex_website_manager_utils::logQuery($log, $sql, 'INSERT INTO `' . $newTablePrefix . 'file` SELECT * FROM ' . $sourceTablePrefix . 'file');
         $src = $REX['FRONTEND_PATH'] . '/' . rex_website::constructMediaDir($sourceWebsiteId);
         $files = glob($src . '/*.*');
         foreach ($files as $file) {
             $targetFile = str_replace(rex_website::constructMediaDir($sourceWebsiteId), rex_website::constructMediaDir($newWebsiteId), $file);
             $logMsg = '[COPY FILE] Source: ' . $file . ' | Target: ' . $targetFile;
             if (copy($file, $targetFile)) {
                 $log->logInfo($logMsg);
             } else {
                 $log->logError($logMsg);
             }
         }
     }
     // copy string table data
     if ($REX['ADDON']['siteclone']['settings']['clone_strings']) {
         rex_website_manager_utils::logQuery($log, $sql, 'INSERT INTO `' . $newTablePrefix . 'string_table` SELECT * FROM ' . $sourceTablePrefix . 'string_table ORDER BY priority');
         // empty string table values
         if ($REX['ADDON']['siteclone']['settings']['empty_strings']) {
             $stringTableFields = $sql->getArray('SELECT * FROM `' . $newTablePrefix . 'string_table` LIMIT 1');
             $values = 'SET value_0 = ""';
             foreach ($stringTableFields[0] as $key => $value) {
                 if (preg_match('/value./', $key)) {
                     if ($key != 'value_0') {
                         $values .= ',' . $key . ' = ""';
                     }
                 }
             }
             rex_website_manager_utils::logQuery($log, $sql, 'UPDATE `' . $newTablePrefix . 'string_table` ' . $values);
         }
     }
     // copy file
     if ($REX['ADDON']['siteclone']['settings']['copy_file'] != '') {
         $sourceFile = str_replace('{id}', $sourceWebsiteId, $REX['ADDON']['siteclone']['settings']['copy_file']);
         $targetFile = str_replace('{id}', $newWebsiteId, $REX['ADDON']['siteclone']['settings']['copy_file']);
         $sourceFile = $REX['FRONTEND_PATH'] . DIRECTORY_SEPARATOR . trim($sourceFile, './');
         $targetFile = $REX['FRONTEND_PATH'] . DIRECTORY_SEPARATOR . trim($targetFile, './');
         $logMsg = '[COPY FILE] Source: ' . $sourceFile . ' | Target: ' . $targetFile;
         if (copy($sourceFile, $targetFile)) {
             $log->logInfo($logMsg);
         } else {
             $log->logError($logMsg);
         }
     }
 }
 public static function destroyWebsite($websiteId)
 {
     global $REX, $I18N;
     $sql = rex_sql::factory();
     $tablePrefix = rex_website::constructTablePrefix($websiteId);
     $generatedDir = rex_website::constructGeneratedDir($websiteId);
     $mediaDir = rex_website::constructMediaDir($websiteId);
     // init logger
     $logFile = WEBSITE_MANAGER_LOG_DIR;
     $log = KLogger::instance($logFile, KLogger::INFO);
     $log->logInfo('======================================== DESTROY WEBSITE WITH ID = ' . $websiteId . ' ========================================');
     // just for security reasons
     if ($websiteId == rex_website::firstId) {
         $log->logError('Website ID = 1 detected --> Exit!');
         echo rex_warning($I18N->msg('website_manager_destroy_website_security_msg'));
         exit;
     }
     // include custom php file with additional userdefined stuff
     require_once WEBSITE_MANAGER_CUSTOM_DIR . 'destroy_website.before.inc.php';
     // extension point
     rex_register_extension_point('WEBSITE_BEFORE_DESTROYED', array('website_id' => $websiteId, 'sql_object' => $sql, 'table_prefix' => $tablePrefix, 'generated_dir' => $generatedDir, 'media_dir' => $mediaDir, 'log_object' => $log));
     // ***************************************************************************************************
     // database views
     // ***************************************************************************************************
     // users
     rex_website_manager_utils::logQuery($log, $sql, 'DROP VIEW ' . $tablePrefix . 'user');
     // clangs
     if ($REX['WEBSITE_MANAGER_SETTINGS']['identical_clangs']) {
         rex_website_manager_utils::logQuery($log, $sql, 'DROP VIEW ' . $tablePrefix . 'clang');
     }
     // media
     if ($REX['WEBSITE_MANAGER_SETTINGS']['identical_media']) {
         rex_website_manager_utils::logQuery($log, $sql, 'DROP VIEW ' . $tablePrefix . 'file');
         rex_website_manager_utils::logQuery($log, $sql, 'DROP VIEW ' . $tablePrefix . 'file_category');
     }
     // modules
     if ($REX['WEBSITE_MANAGER_SETTINGS']['identical_modules']) {
         rex_website_manager_utils::logQuery($log, $sql, 'DROP VIEW ' . $tablePrefix . 'module');
         rex_website_manager_utils::logQuery($log, $sql, 'DROP VIEW ' . $tablePrefix . 'module_action');
         rex_website_manager_utils::logQuery($log, $sql, 'DROP VIEW ' . $tablePrefix . 'action');
     }
     // templates
     if ($REX['WEBSITE_MANAGER_SETTINGS']['identical_templates']) {
         rex_website_manager_utils::logQuery($log, $sql, 'DROP VIEW ' . $tablePrefix . 'template');
     }
     // meta infos
     if ($REX['WEBSITE_MANAGER_SETTINGS']['identical_meta_infos']) {
         rex_website_manager_utils::logQuery($log, $sql, 'DROP VIEW ' . $tablePrefix . '62_type');
         rex_website_manager_utils::logQuery($log, $sql, 'DROP VIEW ' . $tablePrefix . '62_params');
     }
     // image types
     if ($REX['WEBSITE_MANAGER_SETTINGS']['identical_image_types']) {
         rex_website_manager_utils::logQuery($log, $sql, 'DROP VIEW ' . $tablePrefix . '679_types');
         rex_website_manager_utils::logQuery($log, $sql, 'DROP VIEW ' . $tablePrefix . '679_type_effects');
     }
     // ***************************************************************************************************
     // database tables
     // ***************************************************************************************************
     $tables = $sql->showTables(1, $tablePrefix);
     for ($i = 0; $i < count($tables); $i++) {
         rex_website_manager_utils::logQuery($log, $sql, 'DROP TABLE ' . $tables[$i]);
     }
     // ***************************************************************************************************
     // directories
     // ***************************************************************************************************
     $generatedPath = realpath($REX['HTDOCS_PATH'] . 'redaxo/include/') . DIRECTORY_SEPARATOR . $generatedDir;
     $mediaPath = realpath($REX['HTDOCS_PATH']) . DIRECTORY_SEPARATOR . $mediaDir;
     rex_website_manager_utils::rrmdir($generatedPath);
     if (is_dir($generatedPath)) {
         $log->logError('[REMOVE DIR] ' . $generatedPath);
     } else {
         $log->logInfo('[REMOVE DIR] ' . $generatedPath);
     }
     if (!$REX['WEBSITE_MANAGER_SETTINGS']['identical_media']) {
         rex_website_manager_utils::rrmdir($mediaPath);
         if (is_dir($mediaPath)) {
             $log->logError('[REMOVE DIR] ' . $mediaPath);
         } else {
             $log->logInfo('[REMOVE DIR] ' . $mediaPath);
         }
     }
     // include custom php file with additional userdefined stuff
     require_once WEBSITE_MANAGER_CUSTOM_DIR . 'destroy_website.after.inc.php';
     // extension point
     rex_register_extension_point('WEBSITE_AFTER_DESTROYED', array('website_id' => $websiteId, 'sql_object' => $sql, 'table_prefix' => $tablePrefix, 'generated_dir' => $generatedDir, 'media_dir' => $mediaDir, 'log_object' => $log));
 }