Skip to content

Commit

Permalink
Merge branch 'master' of github.com:mozilla/socorro into 2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonsavage committed Oct 10, 2011
2 parents f3bc6f6 + 85f9f0c commit 5e55075
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 75 deletions.
24 changes: 11 additions & 13 deletions webapp-php/application/controllers/admin.php
Expand Up @@ -118,9 +118,8 @@ public function branch_data_sources()
{
if (isset($_POST['action_add_version'])) {
if (
!empty($_POST['product']) &&
!empty($_POST['version']) &&
!empty($_POST['branch']) &&
!empty($_POST['product']) &&
!empty($_POST['version']) &&
!empty($_POST['start_date']) &&
!empty($_POST['end_date']) &&
!empty($_POST['throttle'])
Expand All @@ -133,10 +132,9 @@ public function branch_data_sources()
);
$throttle = (!is_numeric($_POST['throttle']) || $_POST['throttle'] > 100) ? 100 : $_POST['throttle'];
if ($rv = $this->branch_model->add(
trim($_POST['product']),
trim($_POST['version']),
trim($_POST['branch']),
trim($_POST['start_date']),
trim($_POST['product']),
trim($_POST['version']),
trim($_POST['start_date']),
trim($_POST['end_date']),
$featured,
$throttle
Expand All @@ -152,9 +150,9 @@ public function branch_data_sources()
}
elseif (isset($_POST['action_update_version'])) {
if (
!empty($_POST['update_product']) &&
!empty($_POST['update_version']) &&
!empty($_POST['update_start_date']) &&
!empty($_POST['update_product']) &&
!empty($_POST['update_version']) &&
!empty($_POST['update_start_date']) &&
!empty($_POST['update_end_date']) &&
!empty($_POST['update_throttle'])
) {
Expand All @@ -166,9 +164,9 @@ public function branch_data_sources()
);
$throttle = (!is_numeric($_POST['update_throttle']) || $_POST['update_throttle'] > 100) ? 100 : $_POST['update_throttle'];
if ($rv = $this->branch_model->update(
trim($_POST['update_product']),
trim($_POST['update_version']),
trim($_POST['update_start_date']),
trim($_POST['update_product']),
trim($_POST['update_version']),
trim($_POST['update_start_date']),
trim($_POST['update_end_date']),
$featured,
$throttle
Expand Down
68 changes: 6 additions & 62 deletions webapp-php/application/models/branch.php
Expand Up @@ -82,47 +82,19 @@ private function _sortVersions($versions)
* @param float The throttle value for this version.
* @return object The database query object
*/
public function add($product, $version, $branch, $start_date, $end_date, $featured=false, $throttle) {
public function add($product, $version, $start_date, $end_date, $featured=false, $throttle) {
if ($product_version = $this->getByProductVersion($product, $version)) {
return $this->update($product, $version, $branch, $start_date, $end_date, $featured, $throttle);
return $this->update($product, $version, $start_date, $end_date, $featured, $throttle);
} else {
$release = $this->determine_release($version);
try {
$rv = $this->db->query("/* soc.web branch.add */
INSERT INTO productdims (product, version, branch, release)
VALUES (?, ?, ?, ?)",
$product, $version, $branch, $release
);
$rv = $this->db->query("/* soc.web branch.add */
SELECT * FROM edit_product_info(null, ?, ?, ?, ?, ?, ?, ?)", $product, $version, $release, $start_date, $end_date, $featured, $throttle);
} catch (Exception $e) {
Kohana::log('error', "Could not add \"$product\" \"$version\" in soc.web branch.add \r\n " . $e->getMessage());
}
$this->addProductVisibility($product, $version, $start_date, $end_date, $featured, $throttle);
if (isset($rv)) {
return $rv;
}
return $rv;
}
}

/**
* Fetch a product from the productdims table, and add a new record to the product_visibility table.
*
* @access private
* @param string The product name (e.g. 'Camino', 'Firefox', 'Seamonkey, 'Thunderbird')
* @param string The version number (e.g. '3.5', '3.5.1', '3.5.1pre', '3.5.2', '3.5.2pre')
* @param string The release date for this product YYYY-MM-DD
* @param string The end date for this product YYYY-MM-DD (usually +90 days)
* @param bool True if version should be featured on the dashboard; false if not.
* @param float The throttle value for this version.
* @return void
*/
private function addProductVisibility($product, $version, $start_date, $end_date, $featured=false, $throttle) {
$this->db->query("/* soc.web branch.addProductVisibility */
INSERT INTO product_visibility (productdims_id, start_date, end_date, featured, throttle)
SELECT id, ? as start_date, ? as end_date, ? as featured, ? as throttle
FROM productdims
WHERE product = ? AND version = ?
", $start_date, $end_date, $featured, $throttle, $product, $version
);
}

/**
Expand Down Expand Up @@ -365,7 +337,7 @@ public function getNonCurrentProductVersions($delete_cache=false) {
*/
public function getCurrentProductVersions($delete_cache=false) {
$date = date("Y-m-d");
$sql = "/* soc.web branch.getCurrentProductVersions */
$sql = "/* soc.web branch.getCurrentProductVersions */
SELECT DISTINCT pd.product_name as product, pd.version_string as version, is_featured as featured, build_type as release, start_date, end_date, throttle
FROM product_info pd
WHERE pd.start_date <= timestamp without time zone '".$date."'
Expand Down Expand Up @@ -691,34 +663,6 @@ public function update($product, $version, $start_date, $end_date, $featured=fa
return $rv;
}

/**
* Update the start_date and end_date fields of an existing record in the branches view,
* via the productdims tables.
*
* @access private
* @param string The product name (e.g. 'Camino', 'Firefox', 'Seamonkey, 'Thunderbird')
* @param string The version number (e.g. '3.5', '3.5.1', '3.5.1pre', '3.5.2', '3.5.2pre')
* @param string The start date for this product YYYY-MM-DD
* @param string The end date for this product YYYY-MM-DD (usually +90 days)
* @param bool True if version should be featured on the dashboard; false if not.
* @param float The throttle value for this version
* @return void
*/
private function updateProductVisibility($product, $version, $start_date, $end_date, $featured=false, $throttle) {
if ($product_version = $this->getByProductVersion($product, $version)) {
if ($product_visibility = $this->getProductVisibility($product_version->id)) {
$sql = "/* soc.web branch.updateProductVisibility */
UPDATE product_visibility
SET start_date = ?, end_date = ?, featured = ?, throttle = ?
WHERE productdims_id = ?
";
$this->db->query($sql, trim($start_date), trim($end_date), $featured, $throttle, $product_version->id);
} else {
$this->addProductVisibility($product, $version, $start_date, $end_date, $featured, $throttle);
}
}
}

/**
* Given a list of versions for a product, returns only the
* versions which are in the system.
Expand Down

0 comments on commit 5e55075

Please sign in to comment.