setupMusicDirectory(); } else { self::$message = "Invalid path!"; self::$errors[] = self::MEDIA_FOLDER; } // Finalize and move airtime.conf.temp if (file_exists("/etc/airtime/")) { if (!$this->moveAirtimeConfig()) { self::$message = "Error moving airtime.conf or deleting /tmp/airtime.conf.temp!"; self::$errors[] = "ERR"; } if (!$this->moveRmqConfig()) { self::$message = "Error moving rabbitmq-analyzer.ini or deleting /tmp/rabbitmq.ini.tmp!"; self::$errors[] = "ERR"; } /* * If we're upgrading from an old Airtime instance (pre-2.5.2) we rename their old * airtime.conf to airtime.conf.tmp during the setup process. Now that we're done, * we can rename it to airtime.conf.bak to avoid confusion. */ if (file_exists(self::AIRTIME_CONF_PATH . ".tmp")) { rename(self::AIRTIME_CONF_PATH . ".tmp", self::AIRTIME_CONF_PATH . ".bak"); } } else { self::$message = "Failed to move airtime.conf; /etc/airtime doesn't exist!"; self::$errors[] = "ERR"; } return array( "message" => self::$message, "errors" => self::$errors ); } /** * Moves /tmp/airtime.conf.temp to /etc/airtime.conf and then removes it to complete setup * @return boolean false if either of the copy or removal operations fail */ function moveAirtimeConfig() { return copy(AIRTIME_CONF_TEMP_PATH, self::AIRTIME_CONF_PATH) && unlink(AIRTIME_CONF_TEMP_PATH); } /** * Moves /tmp/airtime.conf.temp to /etc/airtime.conf and then removes it to complete setup * @return boolean false if either of the copy or removal operations fail */ function moveRmqConfig() { return copy(RMQ_INI_TEMP_PATH, self::RMQ_INI_BASE_PATH . self::RMQ_INI_FILE_NAME) && copy(RMQ_INI_TEMP_PATH, self::RMQ_INI_BASE_PATH . "production/" . self::RMQ_INI_FILE_NAME) && unlink(RMQ_INI_TEMP_PATH); } /** * Add the given directory to cc_music_dirs * TODO Should we check for an existing entry in cc_music_dirs? */ function setupMusicDirectory() { try { $_SERVER['AIRTIME_CONF'] = AIRTIME_CONF_TEMP_PATH; Propel::init(CONFIG_PATH . "airtime-conf-production.php"); $con = Propel::getConnection(); } catch(Exception $e) { self::$message = "Failed to insert media folder; database isn't configured properly!"; self::$errors[] = self::MEDIA_FOLDER; return; } $this->runMusicDirsQuery($con); } function runMusicDirsQuery($con) { try { if ($this->checkMusicDirectoryExists($con)) { $dir = CcMusicDirsQuery::create()->findPk(1, $con); } else { $dir = new CcMusicDirs(); } $dir->setDirectory(self::$path) ->setType("stor") ->save(); self::$message = "Successfully set up media folder!"; Propel::close(); unset($_SERVER['AIRTIME_CONF']); } catch (Exception $e) { self::$message = "Failed to insert " . self::$path . " into cc_music_dirs"; self::$errors[] = self::MEDIA_FOLDER; } } function checkMusicDirectoryExists($con) { $entry = CcMusicDirsQuery::create()->findPk(1, $con); return isset($entry) && $entry; } }