function camp_remove_dir($p_dirName)
{
    $p_dirName = str_replace('//', '/', $p_dirName);
    $dirBaseName = trim($p_dirName, '/');
    if ($p_dirName == "/" || $dirBaseName == ''
            || $dirBaseName == '.' || $dirBaseName == '..'
            || (strpos($dirBaseName, '/') === false && $p_dirName[0] == '/')) {
        return false;
    }
    if (empty($p_msg)) {
        $p_msg = "Unable to remove directory '$p_dirName'";
    }

    $removeDir = true;
    if (strrpos($p_dirName, '*') == (strlen($p_dirName) - 1)) {
        $p_dirName = substr($p_dirName, 0, strlen($p_dirName) - 1);
        $removeDir = false;
    }
    $p_dirName = rtrim($p_dirName, '/');

    $dirContent = scandir($p_dirName);
    if ($dirContent === false) {
        return false;
    }
    foreach ($dirContent as $file) {
        if (in_array($file, $p_skip)) {
                continue;
        }
        if ($file == '.' || $file == '..') {
            continue;
        }
        $filePath = "$p_dirName/$file";
        if (is_dir($filePath)) {
            camp_remove_dir($filePath);
            continue;
        }
        if (!unlink($filePath)) {
            return false;
        }
    }
    if ($removeDir) {
        rmdir($p_dirName);
    }
}
Пример #2
0
    /**
     *
     */
    private function loadDemoSite()
    {
        global $g_db;
        $session = CampSession::singleton();
        $template_name = $session->getData('config.demo', 'installation');
        $isWritable = true;
        $directories = array();
        $templatesDir = CS_PATH_TEMPLATES;
        $cssDir = $templatesDir.DIR_SEP.'css';
        $imagesDir = $templatesDir.DIR_SEP.'img';
        if (!is_dir($templatesDir) || !is_writable($templatesDir)) {
            $directories[] = $templatesDir;
            $isWritable = false;
        }
        if ((!is_dir($cssDir) && !mkdir($cssDir)) || !is_writable($cssDir)) {
            $directories[] = $cssDir;
            $isWritable = false;
        }
        if ((!is_dir($imagesDir) && !mkdir($imagesDir)) || !is_writable($imagesDir)) {
            $directories[] = $imagesDir;
            $isWritable = false;
        }

        if (!$isWritable) {
            $dirList = implode('<br />', $directories);
            $this->m_step = 'loaddemo';
            $this->m_message = 'Error: Templates directories'
                . '<div class="nonwritable"><em>'.$dirList
                . '</font></em></div>'
                . 'are not writable, please set the appropiate '
                . 'permissions in order to install the demo site files.';
            return false;
        }

        require_once($GLOBALS['g_campsiteDir'].'/bin/cli_script_lib.php');
        camp_remove_dir(CS_PATH_TEMPLATES.DIR_SEP.'*', null, array('system_templates'));

        // copies template files to corresponding directory
        $source = CS_INSTALL_DIR.DIR_SEP.'sample_templates'.DIR_SEP.$template_name['loaddemo'].DIR_SEP.'templates';
        $target = CS_PATH_TEMPLATES;
        if (CampInstallationBaseHelper::CopyFiles($source, $target) == false) {
            $this->m_step = 'loaddemo';
            $this->m_message = 'Error: Copying sample site files';
            return false;
        }

        // copies template data files to corresponding directories.
        // data files are article images and article attachments
        $source = CS_INSTALL_DIR.DIR_SEP.'sample_data';
        $target = CS_PATH_SITE;
        if (CampInstallationBaseHelper::CopyFiles($source, $target) == false) {
            $this->m_step = 'loaddemo';
            $this->m_message = 'Error: Copying sample site data files';
            die('failed');
            return false;
        }

        if (CampInstallationBaseHelper::ConnectDB() == false) {
            $this->m_step = 'loaddemo';
            $this->m_message = 'Error: Database parameters invalid. Could not '
                . 'connect to database server.';
            return false;
        }

        $sqlFile = CS_INSTALL_DIR.DIR_SEP.'sql'.DIR_SEP.'campsite_demo_tables.sql';
        $errors = CampInstallationBaseHelper::ImportDB($sqlFile, $errorQueries);
        if ($errors > 0) {
            $this->m_step = 'loaddemo';
            $this->m_message = 'Error: Importing Database: demo tables';
            foreach ($errorQueries as $query) {
                $this->m_message .= "<br>$query";
            }
            return false;
        }

        $sqlFile = CS_INSTALL_DIR.DIR_SEP.'sql'.DIR_SEP.'campsite_demo_prepare.sql';
        $errors = CampInstallationBaseHelper::ImportDB($sqlFile, $errorQueries);
        if ($errors > 0) {
            $this->m_step = 'loaddemo';
            $this->m_message = 'Error: Importing Database: demo prepare file';
            foreach ($errorQueries as $query) {
                $this->m_message .= "<br>$query";
            }
            return false;
        }

        $sqlFile = CS_INSTALL_DIR.DIR_SEP.'sql'.DIR_SEP.'campsite_demo_data.sql';
        $errors = CampInstallationBaseHelper::ImportDB($sqlFile, $errorQueries);
        if ($errors > 0) {
            $this->m_step = 'loaddemo';
            $this->m_message = 'Error: Importing Database: demo data';
            foreach ($errorQueries as $query) {
                $this->m_message .= "<br>$query";
            }
            return false;
        }

        return true;
    } // fn loadDemoSite
Пример #3
0
/**
 * Remove the specified directory and everything underneath it.
 *
 * @param string $p_dirName
 * @param string $p_msg
 * @param array $p_skip
 *      Array of files or directories to preserve
 * @return void
 */
function camp_remove_dir($p_dirName, $p_msg = "", $p_skip = array())
{
    $p_dirName = str_replace('//', '/', $p_dirName);
    $dirBaseName = trim($p_dirName, '/');
    if ($p_dirName == "/" || $dirBaseName == '' || $dirBaseName == '.' || $dirBaseName == '..' || strpos($dirBaseName, '/') === false && $p_dirName[0] == '/') {
        camp_exit_with_error("camp_remove_dir: Bad directory name '{$p_dirName}'.");
    }
    if (empty($p_msg)) {
        $p_msg = "Unable to remove directory '{$p_dirName}'";
    }
    $removeDir = true;
    if (strrpos($p_dirName, '*') == strlen($p_dirName) - 1) {
        $p_dirName = substr($p_dirName, 0, strlen($p_dirName) - 1);
        $removeDir = false;
    }
    $p_dirName = rtrim($p_dirName, '/');
    $dirContent = scandir($p_dirName);
    if ($dirContent === false) {
        camp_exit_with_error("Unable to read the content of the directory '{$p_dirName}'.");
    }
    foreach ($dirContent as $file) {
        if (in_array($file, $p_skip)) {
            continue;
        }
        if ($file == '.' || $file == '..') {
            continue;
        }
        $filePath = "{$p_dirName}/{$file}";
        if (is_dir($filePath)) {
            camp_remove_dir($filePath);
            continue;
        }
        if (!unlink($filePath)) {
            camp_exit_with_error("Unable to delete the file '{$filePath}'.");
        }
    }
    if ($removeDir) {
        rmdir($p_dirName);
    }
}
Пример #4
0
 /**
  *
  */
 private function loadDemoSite()
 {
     global $g_db;
     $session = CampSession::singleton();
     $template_name = $session->getData('config.demo', 'installation');
     $isWritable = true;
     $directories = array();
     $templatesDir = CS_PATH_TEMPLATES;
     $cssDir = $templatesDir . DIR_SEP . 'css';
     $imagesDir = $templatesDir . DIR_SEP . 'img';
     if (!is_dir($templatesDir) || !is_writable($templatesDir)) {
         $directories[] = $templatesDir;
         $isWritable = false;
     }
     if (!is_dir($cssDir) && !mkdir($cssDir) || !is_writable($cssDir)) {
         $directories[] = $cssDir;
         $isWritable = false;
     }
     if (!is_dir($imagesDir) && !mkdir($imagesDir) || !is_writable($imagesDir)) {
         $directories[] = $imagesDir;
         $isWritable = false;
     }
     if (!$isWritable) {
         $dirList = implode('<br />', $directories);
         $this->m_step = 'loaddemo';
         $this->m_message = 'Error: Templates directories' . '<div class="nonwritable"><em>' . $dirList . '</font></em></div>' . 'are not writable, please set the appropiate ' . 'permissions in order to install the demo site files.';
         return false;
     }
     require_once $GLOBALS['g_campsiteDir'] . '/bin/cli_script_lib.php';
     if (is_dir(CS_PATH_TEMPLATES . DIR_SEP . ThemeManagementServiceLocal::FOLDER_UNASSIGNED)) {
         CampInstallationBaseHelper::CopyFiles(CS_PATH_TEMPLATES . DIR_SEP . ThemeManagementServiceLocal::FOLDER_UNASSIGNED, CS_INSTALL_DIR . DIR_SEP . 'temp');
     }
     camp_remove_dir(CS_PATH_TEMPLATES . DIR_SEP . '*', null, array('system_templates'));
     // copies template files to corresponding directory
     $source = CS_INSTALL_DIR . DIR_SEP . 'sample_templates' . DIR_SEP . $template_name['loaddemo'] . DIR_SEP . 'templates';
     $target = CS_PATH_TEMPLATES . DIR_SEP . ThemeManagementServiceLocal::FOLDER_UNASSIGNED;
     if (CampInstallationBaseHelper::CopyFiles($source, $target) == false) {
         $this->m_step = 'loaddemo';
         $this->m_message = 'Error: Copying sample site files';
         return false;
     }
     // copies template data files to corresponding directories.
     // data files are article images and article attachments
     $source = CS_INSTALL_DIR . DIR_SEP . 'sample_data';
     $target = CS_PATH_SITE;
     if (CampInstallationBaseHelper::CopyFiles($source, $target) == false) {
         $this->m_step = 'loaddemo';
         $this->m_message = 'Error: Copying sample site data files';
         die('failed');
         return false;
     }
     if (CampInstallationBaseHelper::ConnectDB() == false) {
         $this->m_step = 'loaddemo';
         $this->m_message = 'Error: Database parameters invalid. Could not ' . 'connect to database server.';
         return false;
     }
     $sqlFile = CS_INSTALL_DIR . DIR_SEP . 'sql' . DIR_SEP . 'campsite_demo_tables.sql';
     $errors = CampInstallationBaseHelper::ImportDB($sqlFile, $errorQueries);
     if ($errors > 0) {
         $this->m_step = 'loaddemo';
         $this->m_message = 'Error: Importing Database: demo tables';
         foreach ($errorQueries as $query) {
             $this->m_message .= "<br>{$query}";
         }
         return false;
     }
     $sqlFile = CS_INSTALL_DIR . DIR_SEP . 'sql' . DIR_SEP . 'campsite_demo_prepare.sql';
     $errors = CampInstallationBaseHelper::ImportDB($sqlFile, $errorQueries);
     if ($errors > 0) {
         $this->m_step = 'loaddemo';
         $this->m_message = 'Error: Importing Database: demo prepare file';
         foreach ($errorQueries as $query) {
             $this->m_message .= "<br>{$query}";
         }
         return false;
     }
     $sqlFile = CS_INSTALL_DIR . DIR_SEP . 'sql' . DIR_SEP . 'campsite_demo_data.sql';
     $errors = CampInstallationBaseHelper::ImportDB($sqlFile, $errorQueries);
     if ($errors > 0) {
         $this->m_step = 'loaddemo';
         $this->m_message = 'Error: Importing Database: demo data';
         foreach ($errorQueries as $query) {
             $this->m_message .= "<br>{$query}";
         }
         return false;
     }
     // add session db settings into global Campsite
     $keyMap = array('DATABASE_SERVER_ADDRESS' => 'hostname', 'DATABASE_NAME' => 'database', 'DATABASE_USER' => 'username', 'DATABASE_PASSWORD' => 'userpass');
     if (!isset($GLOBALS['Campsite'])) {
         $GLOBALS['Campsite'] = array();
     }
     foreach ($keyMap as $globalKey => $sessionKey) {
         $GLOBALS['Campsite'][$globalKey] = $_SESSION['installation']['config.db'][$sessionKey];
     }
     // bootstrap doctrine
     $GLOBALS['application']->bootstrap('container');
     $resourceId = new Newscoop\Service\Resource\ResourceId(__CLASS__);
     $themeService = $resourceId->getService(IThemeManagementService::NAME_1);
     $publicationService = $resourceId->getService(IPublicationService::NAME);
     foreach ($themeService->getUnassignedThemes() as $theme) {
         foreach ($publicationService->getEntities() as $publication) {
             $themeService->assignTheme($theme, $publication);
         }
     }
     if (is_dir(CS_INSTALL_DIR . DIR_SEP . 'temp')) {
         CampInstallationBaseHelper::CopyFiles(CS_INSTALL_DIR . DIR_SEP . 'temp', CS_PATH_TEMPLATES . DIR_SEP . ThemeManagementServiceLocal::FOLDER_UNASSIGNED);
         camp_remove_dir(CS_INSTALL_DIR . DIR_SEP . 'temp');
     }
     return true;
 }