// This to avoid hang, see http://php.net/manual/es/function.proc-open.php#89338 $transcode_error = fread($transcoder['stderr'], 4096); if (!empty($transcode_error)) { debug_event('play', 'Transcode stderr: ' . $transcode_error, 1); } fclose($transcoder['stderr']); } } // If this is a democratic playlist remove the entry. // We do this regardless of play amount. if ($demo_id && isset($democratic)) { $democratic->delete_from_oid($oid, $type); } // Close sql connection // Warning: do not call functions requiring sql after this point Dba::disconnect(); // Free the session write lock // Warning: Do not change any session variable after this call session_write_close(); $browser->downloadHeaders($media_name, $mime, false, $stream_size); $bytes_streamed = 0; // Actually do the streaming $buf_all = ''; $r_arr = array($fp); $w_arr = $e_arr = null; $status = stream_select($r_arr, $w_arr, $e_arr, 2); if ($status === false) { debug_event('play', 'stream_select failed.', 1); } elseif ($status > 0) { do { $read_size = $transcode ? 2048 : min(2048, $stream_size - $bytes_streamed);
/** * install_insert_db * * Inserts the database using the values from Config. */ function install_insert_db($db_user = null, $db_pass = null, $create_db = true, $overwrite = false, $create_tables = true) { $database = AmpConfig::get('database_name'); // Make sure that the database name is valid preg_match('/([^\\d\\w\\_\\-])/', $database, $matches); if (count($matches)) { Error::add('general', T_('Error: Invalid database name.')); return false; } if (!Dba::check_database()) { Error::add('general', sprintf(T_('Error: Unable to make database connection: %s'), Dba::error())); return false; } $db_exists = Dba::read('SHOW TABLES'); if ($db_exists && $create_db) { if ($overwrite) { Dba::write('DROP DATABASE `' . $database . '`'); } else { Error::add('general', T_('Error: Database already exists and overwrite not checked')); return false; } } if ($create_db) { if (!Dba::write('CREATE DATABASE `' . $database . '`')) { Error::add('general', sprintf(T_('Error: Unable to create database: %s'), Dba::error())); return false; } } Dba::disconnect(); // Check to see if we should create a user here if (strlen($db_user) && strlen($db_pass)) { $db_host = AmpConfig::get('database_hostname'); $sql = 'GRANT ALL PRIVILEGES ON `' . Dba::escape($database) . '`.* TO ' . "'" . Dba::escape($db_user) . "'"; if ($db_host == 'localhost' || strpos($db_host, '/') === 0) { $sql .= "@'localhost'"; } $sql .= "IDENTIFIED BY '" . Dba::escape($db_pass) . "' WITH GRANT OPTION"; if (!Dba::write($sql)) { Error::add('general', sprintf(T_('Error: Unable to create user %1$s with permissions to %2$s on %3$s: %4$s'), $db_user, $database, $db_host, Dba::error())); return false; } } // end if we are creating a user if ($create_tables) { $sql_file = AmpConfig::get('prefix') . '/sql/ampache.sql'; $query = fread(fopen($sql_file, 'r'), filesize($sql_file)); $pieces = split_sql($query); $errors = array(); for ($i = 0; $i < count($pieces); $i++) { $pieces[$i] = trim($pieces[$i]); if (!empty($pieces[$i]) && $pieces[$i] != '#') { if (!($result = Dba::write($pieces[$i]))) { $errors[] = array(Dba::error(), $pieces[$i]); } } } } if ($create_db) { $sql = 'ALTER DATABASE `' . $database . '` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci'; Dba::write($sql); } // If they've picked something other than English update default preferences if (AmpConfig::get('lang') != 'en_US') { // FIXME: 31? I hate magic. $sql = 'UPDATE `preference` SET `value`= ? WHERE `id` = 31'; Dba::write($sql, array(AmpConfig::get('lang'))); $sql = 'UPDATE `user_preference` SET `value` = ? WHERE `preference` = 31'; Dba::write($sql, array(AmpConfig::get('lang'))); } return true; }