public function wmGroupDelete($id) { $SQL1 = "SELECT MIN(id) from weathermap_groups where id <> " . $id; $newid = db_fetch_cell($SQL1); # move any maps out of this group into a still-existing one $SQL2 = "UPDATE weathermap_maps set group_id={$newid} where group_id=" . $id; # then delete the group $SQL3 = "DELETE from weathermap_groups where id=" . $id; WMCactiAPI::executeDBQuery($SQL2); WMCactiAPI::executeDBQuery($SQL3); }
/** * @param $mapParameters * @param $configDirectory * @param $outputDirectory * @param $imageFormat * @param $quietLogging * @param $global_debug * @param $mapCount * @param $rrdtool_path * @param $weathermap_error_suppress * @param $weathermap_poller_start_time * @param $total_warnings * @return array */ function weathermap_run_map($mapParameters, $configDirectory, $outputDirectory, $imageFormat, $quietLogging, $global_debug, $mapCount, $rrdtool_path, $weathermap_error_suppress, $weathermap_poller_start_time, $total_warnings) { global $weathermap_debugging; global $weathermap_error_suppress; // reset the warning counter $weathermap_warncount = 0; // this is what will prefix log entries for this map $logTag = "[Map " . $mapParameters['id'] . "] " . $mapParameters['configfile']; wm_debug("{$logTag} - FIRST TOUCH\n"); $runner = new WeatherMapRunner($configDirectory, $outputDirectory, $mapParameters['configfile'], $mapParameters['filehash'], $imageFormat); if ($global_debug === false && ($mapParameters['debug'] == 'on' || $mapParameters['debug'] == 'once')) { $weathermap_debugging = true; $runner->setDebug(true); wm_debug("{$logTag} - Per-map debugging enabled for this map.\n"); } else { $weathermap_debugging = $global_debug; $runner->setDebug(false); } $runner->setRrdtool($rrdtool_path); // Log where we are up to so the Cacti UI can tell someone WMCactiAPI::setConfigOption("weaathermap_last_started_file", $logTag); $runner->LoadMap(); $mapStartTime = microtime(true); weathermap_memory_check("MEM starting {$mapCount}"); // $weathermapObject = new Weathermap; // $weathermapObject->context = "cacti"; // we can grab the rrdtool path from Cacti's config, in this case // $weathermapObject->rrdtool = $rrdtool_path; // $weathermapObject->ReadConfig($mapfile); $runner->applyAllHints($mapParameters); // weathermap_memory_check("MEM postread"); // $weathermapObject->readData(); // weathermap_memory_check("MEM postdata"); if ($quietLogging == 0) { wm_warn("About to write image file. If this is the last message in your log, increase memory_limit in php.ini [WMPOLL01]\n", true); } weathermap_memory_check("MEM pre-render"); // used to write files before moving them into place // $tempImageFilename = $outputDirectory . DIRECTORY_SEPARATOR . $mapParameters['filehash'] . '.tmp.png'; // $imageFilename = $outputDirectory . DIRECTORY_SEPARATOR . $mapParameters['filehash'] . "." . $imageFormat; // $thumbImageFilename = $outputDirectory . DIRECTORY_SEPARATOR . $mapParameters['filehash'] . ".thumb." . $imageFormat; // $thumb48ImageFilename = $outputDirectory . DIRECTORY_SEPARATOR . $mapParameters['filehash'] . ".thumb48." . $imageFormat; // Write the image to a temporary file first - it turns out that libpng is not that fast // and this way we avoid showing half a map // $weathermapObject->drawMapImage($tempImageFilename, $thumbImageFilename, read_config_option("weathermap_thumbsize")); $runner->run(); // // Firstly, don't move or delete anything if the image saving failed // if (file_exists($tempImageFilename)) { // // Don't try and delete a non-existent file (first run) // if (file_exists($imageFilename)) { // unlink($imageFilename); // } // rename($tempImageFilename, $imageFilename); // } // // $gdThumbImage = imagecreatefrompng($thumbImageFilename); // $gdThumb48Image = imagecreatetruecolor(48, 48); // imagecopyresampled($gdThumb48Image, $gdThumbImage, 0, 0, 0, 0, 48, 48, imagesx($gdThumbImage), imagesy($gdThumbImage)); // imagepng($gdThumb48Image, $thumb48ImageFilename); // imagedestroy($gdThumb48Image); // imagedestroy($gdThumbImage); // $configured_imageuri = $weathermapObject->imageuri; // $weathermapObject->imageuri = 'weathermap-cacti-plugin.php?action=viewimage&id=' . $mapParameters['filehash'] . "&time=" . time(); // if ($quietLogging == 0) { // wm_warn("Wrote map to $imageFilename and $thumbImageFilename\n", true); // } $runner->createAllHTML(); $runner->writeDataFile(); // $weathermapObject->writeDataFile($dataFilename); // put back the configured imageuri // $weathermapObject->imageuri = $configured_imageuri; // if an htmloutputfile was configured, output the HTML there too // but using the configured imageuri and imagefilename // if ($weathermapObject->htmloutputfile != "") { // $htmlFilename = $weathermapObject->htmloutputfile; // // $fileHandle = @fopen($htmlFilename, 'w'); // // if ($fileHandle !== false) { // fwrite( // $fileHandle, // $weathermapObject->makeHTML('weathermap_' . $mapParameters['filehash'] . '_imap') // ); // fclose($fileHandle); // wm_debug("Wrote HTML to %s\n", $htmlFilename); // } else { // if (true === file_exists($htmlFilename)) { // wm_warn('Failed to overwrite ' . $htmlFilename // . " - permissions of existing file are wrong? [WMPOLL02]\n"); // } else { // wm_warn('Failed to create ' . $htmlFilename // . " - permissions of output directory are wrong? [WMPOLL03]\n"); // } // } // } // if ($weathermapObject->imageoutputfile != "" && $weathermapObject->imageoutputfile != "weathermap.png" && file_exists($imageFilename)) { // // copy the existing file to the configured location too // @copy($imageFilename, $weathermapObject->imageoutputfile); // } // If archiving is enabled for this map, then save copies with datestamps, for animation etc if ($mapParameters['archiving'] == 'on') { // TODO - additionally save a copy with a datestamp file format $archiveDatestamp = strftime("%Y-%m-%d-%H-%M", $weathermap_poller_start_time); $archiveFilename = $outputDirectory . DIRECTORY_SEPARATOR . sprintf("%s-archive-%s.%s", $mapParameters['filehash'], $archiveDatestamp, $imageFormat); @copy($imageFilename, $archiveFilename); weathermap_manage_archiving($mapParameters['filehash'] . "-archive-", $outputDirectory); } db_execute("update weathermap_maps set titlecache='" . mysql_real_escape_string($runner->getProcessedTitle()) . "' where id=" . intval($mapParameters['id'])); $runner->cleanUp(); unset($runner); // $weathermapObject->cleanUp(); // unset($weathermapObject); $mapEndTime = microtime(true); $mapDuration = $mapEndTime - $mapStartTime; wm_debug("TIME: %s took %f seconds.\n", $mapParameters['configfile'], $mapDuration); weathermap_memory_check("MEM after"); WMCactiAPI::setConfigOption("weaathermap_last_finished_file", $logTag); // if the debug mode was set to once for this map, then that // time has now passed, and it can be turned off again. $newDebugState = $mapParameters['debug']; if ($newDebugState == 'once') { $newDebugState = 'off'; } WMCactiAPI::executeDBQuery(sprintf("update weathermap_maps set warncount=%d, runtime=%f, debug='%s',lastrun=NOW() where id=%d", $weathermap_warncount, $mapDuration, $newDebugState, $mapParameters['id'])); // $total_warnings += $weathermap_warncount; return; }
private function processImages() { // Firstly, don't move or delete anything if the image saving failed if (file_exists($this->workingImageFileName)) { // Don't try and delete a non-existent file (first run) if (file_exists($this->imageOutputFileName)) { unlink($this->imageOutputFileName); } rename($this->workingImageFileName, $this->imageOutputFileName); } $gdThumbImage = imagecreatefrompng($this->thumbnailImageFileName); // TODO - this might not be a PNG $gdThumb48Image = imagecreatetruecolor(48, 48); imagecopyresampled($gdThumb48Image, $gdThumbImage, 0, 0, 0, 0, 48, 48, imagesx($gdThumbImage), imagesy($gdThumbImage)); imagepng($gdThumb48Image, $this->thumbimagefile2); // TODO - this might not be a PNG imagedestroy($gdThumb48Image); imagedestroy($gdThumbImage); $alternateImageOutputFile = $this->mapObject->imageoutputfile; if ($alternateImageOutputFile != "" && $alternateImageOutputFile != "weathermap.png" && file_exists($this->imageOutputFileName)) { // copy the existing file to the configured location too @copy($this->imageOutputFileName, $alternateImageOutputFile); } if (intval($this->mapObject->thumb_width) > 0) { WMCactiAPI::executeDBQuery(sprintf("update weathermap_maps set thumb_width='%d', thumb_height='%d' where id=%d", $this->mapObject->thumb_width, $this->mapObject->thumb_height, $this->mapID)); } }