Exemple #1
0
 function plugin_debate_update()
 {
     require_once $GLOBALS['g_campsiteDir'] . '/install/classes/CampInstallationBase.php';
     $GLOBALS['g_db'] = $GLOBALS['g_ado_db'];
     $errors = CampInstallationBaseHelper::ImportDB(CS_PATH_PLUGINS . DIR_SEP . 'debate' . DIR_SEP . 'install' . DIR_SEP . 'sql' . DIR_SEP . 'update.sql', $error_queries);
     unset($GLOBALS['g_db']);
 }
Exemple #2
0
 function plugin_soundcloud_install()
 {
     global $LiveUserAdmin;
     $LiveUserAdmin->addRight(array('area_id' => 0, 'right_define_name' => 'plugin_soundcloud_preferences', 'has_implied' => 1));
     $LiveUserAdmin->addRight(array('area_id' => 0, 'right_define_name' => 'plugin_soundcloud_browser', 'has_implied' => 1));
     $LiveUserAdmin->addRight(array('area_id' => 0, 'right_define_name' => 'plugin_soundcloud_upload', 'has_implied' => 1));
     $LiveUserAdmin->addRight(array('area_id' => 0, 'right_define_name' => 'plugin_soundcloud_update', 'has_implied' => 1));
     $LiveUserAdmin->addRight(array('area_id' => 0, 'right_define_name' => 'plugin_soundcloud_delete', 'has_implied' => 1));
     $Admin = new UserType(1);
     $Admin->setPermission('plugin_soundcloud_preferences', true);
     $Admin->setPermission('plugin_soundcloud_browser', true);
     $Admin->setPermission('plugin_soundcloud_upload', true);
     $Admin->setPermission('plugin_soundcloud_update', true);
     $Admin->setPermission('plugin_soundcloud_delete', true);
     require_once $GLOBALS['g_campsiteDir'] . '/install/classes/CampInstallationBase.php';
     $GLOBALS['g_db'] = $GLOBALS['g_ado_db'];
     $errors = CampInstallationBaseHelper::ImportDB(CS_PATH_PLUGINS . DIR_SEP . 'soundcloud/install/sql/plugin_soundcloud.sql', $error_queries);
     unset($GLOBALS['g_db']);
 }
    /**
     *
     */
    private function saveCronJobsScripts()
    {
        global $g_db;

        $cronJobs = array('newscoop_autopublish',
                          'newscoop_indexer',
                          'newscoop_notifyendsubs',
                          'newscoop_notifyevents',
                          'newscoop_statistics');

        $template = CampTemplate::singleton();
        $campsiteBinDir = CS_PATH_SITE.DIR_SEP.'bin';
        $template->assign('CAMPSITE_BIN_DIR', CS_PATH_SITE.DIR_SEP.'bin');

        $cmd = 'crontab -l';
        $external = true;
        exec($cmd, $output, $result);
        if ($result != 0) {
            $cmd = 'crontab -';
            exec($cmd, $output, $result);
            if ($result != 0) {
                $external = false;
                if (CampInstallationBaseHelper::ConnectDB() == false) {
                    $this->m_step = 'cronjobs';
                    $this->m_message = 'Error: Database parameters invalid. Could not '
                    . 'connect to database server.';
                    return false;
                }
                $sqlQuery = "UPDATE SystemPreferences SET value = 'N' "
                    ."WHERE varname = 'ExternalCronManagement'";
                $g_db->Execute($sqlQuery);
            }
        }

        $cronJobsDir = CS_INSTALL_DIR.DIR_SEP.'cron_jobs';
        $allAtOnceFile = $cronJobsDir.DIR_SEP.'all_at_once';
        if (file_exists($allAtOnceFile)) {
            unlink($allAtOnceFile);
        }
        $alreadyInstalled = false;
        foreach ($output as $cronLine) {
            if (!file_put_contents($allAtOnceFile, "$cronLine\n", FILE_APPEND)) {
                $error = true;
            }
            if (strstr($cronLine, $campsiteBinDir)) {
                $alreadyInstalled = true;
            }
        }
        if ($alreadyInstalled) {
            return true;
        }

        $buffer = '';
        $isFileWritable = is_writable($cronJobsDir);
        $error = false;
        foreach ($cronJobs as $cronJob) {
            $buffer = $template->fetch('_'.$cronJob.'.tpl');
            $cronJobFile = $cronJobsDir.DIR_SEP.$cronJob;
            if (file_exists($cronJobFile)) {
                $isFileWritable = is_writable($cronJobFile);
            }

            if (!$isFileWritable) {
                // try to unlink existing file
                $isFileWritable = @unlink($cronJobFile);
            }
            if (!$isFileWritable) {
                $error = true;
                continue;
            }
            if (file_put_contents($cronJobFile, $buffer)) {
                $buffer .= "\n";
                if (!file_put_contents($allAtOnceFile, $buffer, FILE_APPEND)) {
                    $error = true;
                }
            } else {
                $error = true;
            }
        }

        if ($error) {
            $this->m_step = 'cronjobs';
            $this->m_message = 'Error: Could not save cron job files. '
                .'Apache user must have write permissions on <em>install/cron_jobs/</em> directory.';
            return false;
        }

        if ($external && file_exists($allAtOnceFile)) {
            $cmd = 'crontab '.escapeshellarg($allAtOnceFile);
            system($cmd);
        }

        return true;
    } // fn saveCronJobsScripts