forked from ThinkUpLLC/ThinkUp
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DB MIGRATION REQ'D] Preserve intermediary short links, closes ThinkU…
- Loading branch information
1 parent
7b50b7a
commit 55001ab
Showing
16 changed files
with
292 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
/** | ||
* | ||
* ThinkUp/tests/TestOfShortLinkMySQLDAO.php | ||
* | ||
* Copyright (c) 2012 Gina Trapani | ||
* | ||
* LICENSE: | ||
* | ||
* This file is part of ThinkUp (http://thinkupapp.com). | ||
* | ||
* ThinkUp is free software: you can redistribute it and/or modify it under the terms of the GNU General Public | ||
* License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any | ||
* later version. | ||
* | ||
* ThinkUp is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied | ||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
* details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with ThinkUp. If not, see | ||
* <http://www.gnu.org/licenses/>. | ||
* | ||
* @license http://www.gnu.org/licenses/gpl.html | ||
* @copyright 2012 Gina Trapani | ||
* @author Gina Trapani <ginatrapani[at]gmail[dot]com> | ||
* | ||
*/ | ||
|
||
require_once dirname(__FILE__).'/init.tests.php'; | ||
require_once THINKUP_WEBAPP_PATH.'_lib/extlib/simpletest/autorun.php'; | ||
require_once THINKUP_WEBAPP_PATH.'config.inc.php'; | ||
|
||
class TestOfShortLinkMySQLDAO extends ThinkUpUnitTestCase { | ||
|
||
public function testCreateNewShortLinkDAO() { | ||
$dao = DAOFactory::getDAO('ShortLinkDAO'); | ||
$this->assertTrue(isset($dao)); | ||
$this->assertIsA($dao, 'ShortLinkMySQLDAO'); | ||
} | ||
|
||
public function testInsert() { | ||
$dao = DAOFactory::getDAO('ShortLinkDAO'); | ||
$result = $dao->insert(12, 'http://t.co/12'); | ||
$this->assertEqual($result, 1); | ||
|
||
$sql = "SELECT * FROM " . $this->table_prefix . 'links_short'; | ||
$stmt = ShortLinkMySQLDAO::$PDO->query($sql); | ||
$data = array(); | ||
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { | ||
array_push($data, $row); | ||
} | ||
$stmt->closeCursor(); | ||
$this->assertEqual(count($data), 1); | ||
$data = $data[0]; | ||
$this->assertEqual($data['id'], 1); | ||
$this->assertEqual($data['link_id'], 12); | ||
$this->assertEqual($data['short_url'], 'http://t.co/12'); | ||
$this->assertEqual($data['click_count'], 0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
/** | ||
* | ||
* ThinkUp/webapp/_lib/model/class.ShortLink.php | ||
* | ||
* Copyright (c) 2012 Gina Trapani | ||
* | ||
* LICENSE: | ||
* | ||
* This file is part of ThinkUp (http://thinkupapp.com). | ||
* | ||
* ThinkUp is free software: you can redistribute it and/or modify it under the terms of the GNU General Public | ||
* License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any | ||
* later version. | ||
* | ||
* ThinkUp is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied | ||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
* details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with ThinkUp. If not, see | ||
* <http://www.gnu.org/licenses/>. | ||
* | ||
* ShortLink | ||
* | ||
* Shortened URLs, potentially many per link object. | ||
* | ||
* @license http://www.gnu.org/licenses/gpl.html | ||
* @copyright 2012 Gina Trapani | ||
* @author Gina Trapani <ginatrapani[at]gmail[dot]com> | ||
* | ||
*/ | ||
|
||
class ShortLink { | ||
/** | ||
* @var int Internal unique ID. | ||
*/ | ||
var $id; | ||
/** | ||
* @var int Expanded link ID in links table. | ||
*/ | ||
var $link_id; | ||
/** | ||
* @var str Shortened URL. | ||
*/ | ||
var $short_url; | ||
/** | ||
* @var int Total number of clicks as reported by shortening service. | ||
*/ | ||
var $click_count; | ||
/** | ||
* @var str Last time the click count was updated from the shortening service. | ||
*/ | ||
var $first_seen; | ||
public function __construct($row = false) { | ||
if ($row) { | ||
$this->id = $row['id']; | ||
$this->link_id = $row['link_id']; | ||
$this->short_url = $row['short_url']; | ||
$this->click_count = $row['click_count']; | ||
$this->first_seen = $row['first_seen']; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
/** | ||
* | ||
* ThinkUp/webapp/_lib/model/class.ShortLinkMySQLDAO.php | ||
* | ||
* Copyright (c) 2012 Gina Trapani | ||
* | ||
* LICENSE: | ||
* | ||
* This file is part of ThinkUp (http://thinkupapp.com). | ||
* | ||
* ThinkUp is free software: you can redistribute it and/or modify it under the terms of the GNU General Public | ||
* License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any | ||
* later version. | ||
* | ||
* ThinkUp is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied | ||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
* details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with ThinkUp. If not, see | ||
* <http://www.gnu.org/licenses/>. | ||
* | ||
* Short Link Data Access Object interface | ||
* | ||
* @license http://www.gnu.org/licenses/gpl.html | ||
* @copyright 2012 Gina Trapani | ||
* @author Gina Trapani <ginatrapani[at]gmail[dot]com> | ||
*/ | ||
class ShortLinkMySQLDAO extends PDODAO { | ||
public function insert($link_id, $short_url) { | ||
$q = "INSERT INTO #prefix#links_short "; | ||
$q .= "(link_id, short_url) "; | ||
$q .= "VALUES (:link_id , :short_url) "; | ||
$vars = array( | ||
':link_id'=>(int)$link_id, | ||
':short_url'=>$short_url | ||
); | ||
$ps = $this->execute($q, $vars); | ||
return $this->getInsertId($ps); | ||
} | ||
} |
Oops, something went wrong.