/**
  * @see Form::validate()
  */
 public function validate()
 {
     parent::validate();
     // validate class path
     if (empty($this->classPath)) {
         throw new UserInputException('classPath');
     }
     try {
         $package = new Package($this->packageID);
         if (!@file_exists(FileUtil::getRealPath(WCF_DIR . $package->getDir() . $this->classPath))) {
             throw new UserInputException('classPath', 'doesNotExist');
         }
     } catch (SystemException $e) {
         throw new UserInputException('classPath', 'doesNotExist');
     }
     try {
         CronjobEditor::validate($this->startMinute, $this->startHour, $this->startDom, $this->startMonth, $this->startDow);
     } catch (SystemException $e) {
         // extract field name
         $fieldName = '';
         if (preg_match("/cronjob attribute '(.*)'/", $e->getMessage(), $match)) {
             $fieldName = $match[1];
         }
         throw new UserInputException($fieldName, 'notValid');
     }
 }
 /**
  * @see CacheBuilder::getData()
  */
 public function getData($cacheResource)
 {
     list($cache, $packageID, $styleID) = explode('-', $cacheResource['cache']);
     $data = array();
     // get active package
     require_once WCF_DIR . 'lib/acp/package/Package.class.php';
     $activePackage = new Package($packageID);
     $activePackageDir = FileUtil::getRealPath(WCF_DIR . $activePackage->getDir());
     // get package dirs
     $packageDirs = array();
     $sql = "SELECT\t\tDISTINCT packageDir\r\n\t\t\tFROM\t\twcf" . WCF_N . "_package_dependency dependency\r\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_package package\r\n\t\t\tON\t\t(package.packageID = dependency.dependency)\r\n\t\t\tWHERE\t\tdependency.packageID = " . $packageID . "\r\n\t\t\t\t\tAND packageDir <> ''\r\n\t\t\tORDER BY\tpriority DESC";
     $result = WCF::getDB()->sendQuery($sql);
     while ($row = WCF::getDB()->fetchArray($result)) {
         $packageDirs[] = FileUtil::getRealPath(WCF_DIR . $row['packageDir']);
     }
     $packageDirs[] = WCF_DIR;
     // get style icon path
     $iconDirs = array();
     $sql = "SELECT\tvariableValue\r\n\t\t\tFROM\twcf" . WCF_N . "_style_variable\r\n\t\t\tWHERE\tstyleID = " . $styleID . "\r\n\t\t\t\tAND variableName = 'global.icons.location'";
     $row = WCF::getDB()->getFirstRow($sql);
     if (!empty($row['variableValue'])) {
         $iconDirs[] = FileUtil::addTrailingSlash($row['variableValue']);
     }
     if (!in_array('icon/', $iconDirs)) {
         $iconDirs[] = 'icon/';
     }
     // get icons
     foreach ($packageDirs as $packageDir) {
         $relativePackageDir = $activePackageDir != $packageDir ? FileUtil::getRelativePath($activePackageDir, $packageDir) : '';
         foreach ($iconDirs as $iconDir) {
             $path = FileUtil::addTrailingSlash($packageDir . $iconDir);
             $icons = self::getIconFiles($path);
             foreach ($icons as $icon) {
                 $icon = str_replace($path, '', $icon);
                 if (!isset($data[$icon])) {
                     $data[$icon] = $relativePackageDir . $iconDir . $icon;
                 }
             }
         }
     }
     return $data;
 }
 /**
  * @see Form::save()
  */
 public function save()
 {
     ACPForm::save();
     // update cronjob
     $this->cronjob->update($this->classPath, $this->packageID, $this->description, $this->execMultiple, $this->startMinute, $this->startHour, $this->startDom, $this->startMonth, $this->startDow);
     $this->saved();
     // delete old entries
     $sql = "DELETE FROM wcf" . WCF_N . "_admin_tools_function_to_cronjob\n\t\t\t\tWHERE cronjobID = " . $this->cronjobID;
     WCF::getDB()->sendQuery($sql);
     $inserts = '';
     foreach ($this->activeFunctions as $functionID) {
         if (!empty($inserts)) {
             $inserts .= ',';
         }
         $inserts .= '(' . $functionID . ', ' . $this->cronjobID . ')';
     }
     $sql = "INSERT IGNORE INTO wcf" . WCF_N . "_admin_tools_function_to_cronjob\n\t\t\t\t\t(functionID, cronjobID)\n\t\t\t\t\tVALUES " . $inserts;
     WCF::getDB()->sendQuery($sql);
     $package = new Package($this->packageID);
     $path = FileUtil::getRealPath(WCF_DIR . $package->getDir());
     $fileName = $path . 'lib/system/cronjob/AdminToolsCronjob' . $this->cronjobID . '.class.php';
     if (file_exists($fileName)) {
         unlink($fileName);
     }
     $this->writeCronjob($this->cronjobID, $fileName);
     $this->saved();
     // show success.
     WCF::getTPL()->assign(array('success' => true));
 }
Ejemplo n.º 4
0
 /**
  * Writes the config.inc.php for a standalone application.
  * 
  * @param	integer		$packageID
  */
 public static function writeConfigFile($packageID)
 {
     $package = new Package($packageID);
     $packageDir = FileUtil::addTrailingSlash(FileUtil::getRealPath(WCF_DIR . $package->getDir()));
     $file = new File($packageDir . PackageInstallation::CONFIG_FILE);
     $file->write("<?php\n");
     $currentPrefix = strtoupper($package->getAbbreviation());
     // get dependencies (only standalones)
     $sql = "SELECT\t\tpackage.*, IF(package.packageID = " . $packageID . ", 1, 0) AS sortOrder\n\t\t\tFROM\t\twcf" . WCF_N . "_package_dependency package_dependency\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_package package\n\t\t\tON\t\t(package.packageID = package_dependency.dependency)\n\t\t\tWHERE\t\tpackage_dependency.packageID = " . $packageID . "\n\t\t\t\t\tAND package.standalone = 1\n\t\t\t\t\tAND package.packageDir <> ''\n\t\t\tORDER BY\tsortOrder DESC,\n\t\t\t\t\tpackage_dependency.priority DESC";
     $result = WCF::getDB()->sendQuery($sql);
     while ($row = WCF::getDB()->fetchArray($result)) {
         $dependency = new Package(null, $row);
         $dependencyDir = FileUtil::addTrailingSlash(FileUtil::getRealPath(WCF_DIR . $dependency->getDir()));
         $prefix = strtoupper($dependency->getAbbreviation());
         $file->write("// " . $dependency->getPackage() . " vars\n");
         $file->write("// " . strtolower($prefix) . "\n");
         $file->write("if (!defined('" . $prefix . "_DIR')) define('" . $prefix . "_DIR', " . ($dependency->getPackageID() == $package->getPackageID() ? "dirname(__FILE__).'/'" : "'" . $dependencyDir . "'") . ");\n");
         $file->write("if (!defined('RELATIVE_" . $prefix . "_DIR')) define('RELATIVE_" . $prefix . "_DIR', " . ($dependency->getPackageID() == $package->getPackageID() ? "''" : "RELATIVE_" . $currentPrefix . "_DIR.'" . FileUtil::getRelativePath($packageDir, $dependencyDir) . "'") . ");\n");
         $file->write("if (!defined('" . $prefix . "_N')) define('" . $prefix . "_N', '" . WCF_N . "_" . $dependency->getInstanceNo() . "');\n");
         $file->write("\$packageDirs[] = " . $prefix . "_DIR;\n");
         $file->write("\n");
     }
     // write general information
     $file->write("// general info\n");
     $file->write("if (!defined('RELATIVE_WCF_DIR'))\tdefine('RELATIVE_WCF_DIR', RELATIVE_" . $currentPrefix . "_DIR.'" . FileUtil::getRelativePath($packageDir, WCF_DIR) . "');\n");
     $file->write("if (!defined('PACKAGE_ID')) define('PACKAGE_ID', " . $package->getPackageID() . ");\n");
     $file->write("if (!defined('PACKAGE_NAME')) define('PACKAGE_NAME', '" . str_replace("'", "\\'", $package->getName()) . "');\n");
     $file->write("if (!defined('PACKAGE_VERSION')) define('PACKAGE_VERSION', '" . $package->getVersion() . "');\n");
     // write end
     $file->write("?>");
     $file->close();
 }