consistency fixes

This commit is contained in:
Bernhard Posselt
2013-02-09 00:06:52 +01:00
parent 9dbbd2e408
commit a98957bcc6
5 changed files with 40 additions and 30 deletions

View File

@@ -32,8 +32,8 @@ The apptemplate comes with several different controllers. A simple controller wo
/**
* @param Request $request: an instance of the request
* @param API $api: an api wrapper instance
* @param Request $request an instance of the request
* @param API $api an api wrapper instance
*/
public function __construct($api, $request){
parent::__construct($api, $request);
@@ -43,7 +43,7 @@ The apptemplate comes with several different controllers. A simple controller wo
/**
* @Ajax
*
* @brief sets a global system value
* sets a global system value
*/
public function myControllerMethod(){
$value = $this->params('somesetting');
@@ -57,7 +57,7 @@ The apptemplate comes with several different controllers. A simple controller wo
?>
An instance of the API is passed via dependency injection, the same goes for a :php:class:`OCA\\AppFramework\\Http\\Request` instance. URL Parameters, POST, GET and FILES parameters are partly abstracted by the Request class and can be accessed via **$this->params('myURLParamOrPostOrGetKey')** and **$this->getUploadedFile($key)** inside the controller. This has been done to make the app better testable.
An instance of the API is passed via :doc:`../general/dependencyinjection`, the same goes for a :php:class:`OCA\\AppFramework\\Http\\Request` instance. URL Parameters, POST, GET and FILES parameters are partly abstracted by the Request class and can be accessed via **$this->params('myURLParamOrPostOrGetKey')** and **$this->getUploadedFile($key)** inside the controller. This has been done to make the app better testable.
.. note:: If an URL Parameter, POST or GET value exist with the same key, the URL Parameter is preferred over the POST parameter and the POST parameter is preferred over the GET parameter. You should avoid this scenario though.

View File

@@ -17,24 +17,25 @@ To make exporting database data really easy, the class **OC_Migration_Content**
function export( ){
OC_Log::write('migration','starting export for bookmarks',OC_Log::INFO);
$options = array(
// migrate two tables
$bookmarkOptions = array(
'table'=>'bookmarks',
'matchcol'=>'user_id',
'matchval'=>$this->uid,
'idcol'=>'id'
);
$ids = $this->content->copyRows( $options );
$options = array(
$bookmarkIds = $this->content->copyRows( $bookmarkOptions );
$bookmarkTagsOptions = array(
'table'=>'bookmarks_tags',
'matchcol'=>'bookmark_id',
'matchval'=>$ids
);
// Export tags
$ids2 = $this->content->copyRows( $options );
$bookmarkTagsIds = $this->content->copyRows( $bookmarkTagsOptions );
// If both returned some ids then they worked
if( is_array( $ids ) && is_array( $ids2 ) )
if( is_array( $bookmarkIds ) && is_array( $bookmarkTagsIds ) )
{
return true;
} else {
@@ -54,7 +55,7 @@ To export the bookmarks, **matchcol** is set to the user_id column and **matchva
Files
~~~~~
If you use files to hold some app data in data/userid/appname, they will be automatically copied exported for you.
If you use files to hold some app data in **data/userid/appname/**, they will be automatically copied exported for you.
Import
------
@@ -71,12 +72,20 @@ Import is a little more tricky as we have to take into account data from differe
// All versions of the app have had the same db structure
// so all can use the same import function
$query = $this->content->prepare( "SELECT * FROM bookmarks WHERE user_id LIKE ?" );
$results = $query->execute( array( $this->olduid ) );
$results = $query->execute( array( $this->olduid ));
$idmap = array();
while( $row = $results->fetchRow() ){
// Import each bookmark, saving its id into the map
$query = OC_DB::prepare( "INSERT INTO *PREFIX*bookmarks(url, title, user_id, public, added, lastmodified) VALUES (?, ?, ?, ?, ?, ?)" );
$query->execute( array( $row['url'], $row['title'], $this->uid, $row['public'], $row['added'], $row['lastmodified'] ) );
$sql = "INSERT INTO *PREFIX*bookmarks(url, title, user_id, public, added, lastmodified) VALUES (?, ?, ?, ?, ?, ?)";
$query = OC_DB::prepare($sql);
$query->execute( array(
$row['url'],
$row['title'],
$this->uid,
$row['public'],
$row['added'],
$row['lastmodified']
) );
// Map the id
$idmap[$row['id']] = OC_DB::insertid();
}
@@ -104,7 +113,7 @@ Remember this part of the import code may be a good place to emit some hooks dep
After importing the bookmarks, we must import the tags. It is a very similar process to importing the bookmarks, except we have to take into account the changes in primary keys. This is done by using a foreach key in the **$idmap** array, and then inserting the tags using the new id.
After all this, we must return a boolean value to indicate the success or failure of the import. Again, app data files stored in data/userid/appname will be automatically copied over before the apps import function is executed, this allows you to manipulate the imported files if necessary.
After all this, we must return a boolean value to indicate the success or failure of the import. Again, app data files stored in **data/userid/appname** will be automatically copied over before the apps import function is executed, this allows you to manipulate the imported files if necessary.
Conclusion
----------

View File

@@ -122,7 +122,7 @@ Your database layer should go into the **db/** folder. It's recommended to split
}
All database queries for that object should be put into a mapper class. This follows the `data mapper pattern <http://www.martinfowler.com/eaaCatalog/dataMapper.html>`_. The mapper class could look like this (more method examples are in the **advancedapptemplate** app):
All database queries for that object should be put into a mapper class. This follows the `data mapper pattern <http://www.martinfowler.com/eaaCatalog/dataMapper.html>`_. The mapper class could look like this (more method examples are in the **Apptemplate Advanced** app):
:file:`db/itemmapper.php`
@@ -141,7 +141,7 @@ All database queries for that object should be put into a mapper class. This fol
private $tableName;
/**
* @param API $api: Instance of the API abstraction layer
* @param API $api Instance of the API abstraction layer
*/
public function __construct($api){
parent::__construct($api);
@@ -151,8 +151,9 @@ All database queries for that object should be put into a mapper class. This fol
/**
* Finds an item by id
* @throws DoesNotExistException: if the item does not exist
* @return the item
* @throws DoesNotExistException if the item does not exists
* @throws MultipleObjectsReturnedException if more than one item exists
* @return Item the item
*/
public function find($id){
$row = $this->findQuery($this->tableName, $id);
@@ -162,9 +163,9 @@ All database queries for that object should be put into a mapper class. This fol
/**
* Finds an item by user id
* @param string $userId: the id of the user that we want to find
* @throws DoesNotExistException: if the item does not exist
* @return the item
* @param string $userId the id of the user that we want to find
* @throws DoesNotExistException if the item does not exist
* @return Item the item
*/
public function findByUserId($userId){
$sql = 'SELECT * FROM ' . $this->tableName . ' WHERE user = ?';
@@ -181,8 +182,8 @@ All database queries for that object should be put into a mapper class. This fol
/**
* Saves an item into the database
* @param Item $item: the item to be saved
* @return the item with the filled in id
* @param Item $item the item to be saved
* @return Item the item with the filled in id
*/
public function save($item){
$sql = 'INSERT INTO '. $this->tableName . '(name, user, path)'.
@@ -225,7 +226,7 @@ All database queries for that object should be put into a mapper class. This fol
/**
* Deletes an item
* @param int $id: the id of the item
* @param int $id the id of the item
*/
public function delete($id){
$this->deleteQuery($this->tableName, $id);

View File

@@ -19,8 +19,8 @@ Using ownCloud stable
~~~~~~~~~~~~~~~~~~~~~
`Install the current version of ownCloud <http://doc.owncloud.org/server/5.0/admin_manual/installation.html>`_ and create a new directory in the **apps/** folder.
Using ownCloud developement version
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Using ownCloud development version
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ownCloud uses `GitHub`_ for developing its code. To be able to participate or check out the code You will have to sign up on `GitHub`_ and install Git.

View File

@@ -79,7 +79,7 @@ The first parameter is the name under which the controller was defined in the :f
The second parameter is the name of the method that should be called on the controller.
The third parameter is the $params array which is passed to the controller and available by using **$this->params($KEY)** in the controller method. In the following example, the parameter in the URL would be accessible by using: **$this->params('key')**
The third parameter is the $params array which is passed to the controller and available by using **$this->params($key)** in the controller method. In the following example, the parameter in the URL would be accessible by using: **$this->params('key')**
You can also limit the route to GET or POST requests by simply adding **->post()** or **->get()** before the action method like:
@@ -96,7 +96,7 @@ You can also limit the route to GET or POST requests by simply adding **->post()
);
?>
The fourth parameter is an instance of the **DIContaier**. If you want to replace objects in the container only for a certain request, you can do it like this:
The fourth parameter is an instance of the **DIContaier** (see :doc:`../general/dependencyinjection`). If you want to replace objects in the container only for a certain request, you can do it like this:
.. code-block:: php