function updateTables($version) { Auth::updateTables($version); Comment::updateTables($version); Feedback::updateTables($version); Journal::updateTables($version); Media::updateTables($version); Setting::updateTables($version); Trip::updateTables($version); TripAttribute::updateTables($version); TripUser::updateTables($version); User::updateTables($version); print "Tables have been updated. "; }
public function testUpdateDatabase() { $version = Setting::getDataVersion(); $this->assertTrue(Auth::updateTables($version, '')); $this->assertTrue(Comment::updateTables($version, '')); $this->assertTrue(Feedback::updateTables($version, '')); $this->assertTrue(Journal::updateTables($version, '')); $this->assertTrue(Media::updateTables($version, '')); $this->assertTrue(Trip::updateTables($version, '')); $this->assertTrue(TripAttribute::updateTables($version, '')); $this->assertTrue(TripUser::updateTables($version, '')); $this->assertTrue(User::updateTables($version, '')); // Note: make sure the Settings::updateTables is last: when any of the // above fail, the data version in the database should NOT be updated! $this->assertTrue(Setting::updateTables($version, '')); }
/** * Test #13. SYNCH request write new object. */ public function testSynchPut() { global $testTripId1, $testName1; global $synchAuthToken; $this->assertEquals(0, $this->countTestRows()); $data = array('tripId' => $testTripId1, 'name' => $testName1, 'created' => '2015-10-01', 'updated' => '2015-10-02', 'value' => 'value', 'deleted' => 'Y', 'hash' => 'forced hash'); $result = putApi('synchTripAttribute.php', $data, $synchAuthToken); $this->assertEquals(RESPONSE_SUCCESS, $result['resultCode']); $this->assertEquals(1, $this->countTestRows()); $object = new TripAttribute($testTripId1, $testName1); $this->assertEquals('2015-10-01 00:00:00.000000', $object->getCreated()); $this->assertEquals('2015-10-02 00:00:00.000000', $object->getUpdated()); $this->assertEquals("Y", $object->getDeleted()); $this->assertEquals('forced hash', $object->getHash()); }
$response['updated'] = $object->getUpdated(); $response['value'] = $object->getValue(); $response['deleted'] = $object->getDeleted(); $response['hash'] = $object->getHash(); } } } else { $response = errorResponse(RESPONSE_BAD_REQUEST); } } else { if (isPutMethod()) { $data = getPostData(); if (isset($data['tripId']) && isset($data['name']) && $data['tripId'] !== '' && $data['name'] !== '') { $tripId = $data['tripId']; $name = $data['name']; $object = new TripAttribute($tripId, $name); if (isset($data['created'])) { $object->setCreated($data['created']); } if (isset($data['updated'])) { $object->setUpdated($data['updated']); } if (isset($data['value'])) { $object->setValue($data['value']); } if (isset($data['deleted'])) { $object->setDeleted($data['deleted']); } if (isset($data['hash'])) { $object->setHash($data['hash']); }
public static function findByHash($hash = '') { if (!isset($hash) || $hash === '') { return null; } $hashValue = db_sql_encode($hash); $query = "SELECT * FROM blogTripAttribute " . "WHERE hash={$hashValue} " . "ORDER BY updated DESC " . "LIMIT 1"; $result = mysql_query($query); if (!$result) { // Error executing the query print $query . "<br/>"; print " --> error: " . mysql_error() . "<br/>\n"; return null; } if (mysql_num_rows($result) <= 0) { // Trip does not exist return null; } // Create a Trip object with a special trip ID '-' to bypass the // checks on empty ID. The ID value will be overwritten by the // value coming back from the database anyway. $trip = new TripAttribute('-', '-'); if ($trip->loadFromResult($result)) { return $trip; } return null; }
include_once dirname(__FILE__) . '/../database/TripAttribute.php'; $auth = new AuthB(); if (!$auth->canGetTripAttribute()) { $response = errorResponse(RESPONSE_UNAUTHORIZED); } else { $tripId = ''; if (isset($_GET['tripId'])) { $tripId = $_GET['tripId']; } $name = ''; if (isset($_GET['name'])) { $name = $_GET['name']; } if ($tripId === '' || $name === '') { $response = errorResponse(RESPONSE_BAD_REQUEST); } else { $object = new TripAttribute($tripId, $name); if ($object->getCreated() === null) { $response = errorResponse(RESPONSE_NOT_FOUND); } else { $response = successResponse(); $response['tripId'] = $object->getTripId(); $response['name'] = $object->getName(); $response['created'] = $object->getCreated(); $response['updated'] = $object->getUpdated(); $response['value'] = $object->getValue(); $response['deleted'] = $object->getDeleted(); } } } echo json_encode($response);
/** * Test #17. * The findByHash function returns an object populated with previous * values if a hash for a previous instance is given. * @depends testUpdate * @depends testHashGetInstance */ public function testHashOldInstance() { global $testTripId1; // create the object and save it $object = new TripAttribute($testTripId1, 'name'); $object->setValue('value'); $object->setDeleted('Y'); $this->assertTrue($object->save()); $this->assertEquals(1, $this->countTestRows()); $old_hash = $object->getHash(); // change values and update the object $object->setValue('value 2'); $object->setDeleted('N'); $this->assertTrue($object->save()); $this->assertEquals(2, $this->countTestRows()); $new_hash = $object->getHash(); // read the object from the database and confirm that the old // values are returned $object = TripAttribute::findByHash($old_hash); $this->assertNotNull($object); $this->assertEquals($testTripId1, $object->getTripId()); $this->assertEquals('name', $object->getName()); $this->assertEquals('value', $object->getValue()); $this->assertEquals('Y', $object->getDeleted()); $this->assertEquals($old_hash, $object->getHash()); // read the new object from the database and confirm that the new // values are returned $object = TripAttribute::findByHash($new_hash); $this->assertNotNull($object); $this->assertEquals($testTripId1, $object->getTripId()); $this->assertEquals('name', $object->getName()); $this->assertEquals('value 2', $object->getValue()); $this->assertEquals('N', $object->getDeleted()); $this->assertEquals($new_hash, $object->getHash()); }
$response = errorResponse(RESPONSE_UNAUTHORIZED); } else { if (isPutMethod()) { $data = getPostData(); $tripId = ''; if (isset($data['tripId'])) { $tripId = $data['tripId']; } $name = ''; if (isset($data['name'])) { $name = $data['name']; } if ($tripId === '' || $name === '') { $response = errorResponse(RESPONSE_BAD_REQUEST); } else { $object = new TripAttribute($tripId, $name); if (isset($data['value'])) { $object->setValue($data['value']); } if (isset($data['deleted'])) { $object->setDeleted($data['deleted']); } if ($object->save()) { $response = successResponse(); } else { $response = errorResponse(RESPONSE_INTERNAL_ERROR); } } } } echo json_encode($response);