ER-Diagram : How to manage sessions ? (parallel drupal <-> symfony2) - drupal

I am building my app and have been annoyed concerning sessions storage. I am a newbie about sessions. I am working with Symfony2 and MySQL, and as Symfony is storage-agnostic, I am searching into the Drupal 7 diagram to find a good model.
So I wondered a couple of things :
How to manage sessions in an Entity-Relationship diagram ?
In drupal 7 diagram, what do sessions->fields mean ?
Sessions -> uid (int(10)) -> OK
Sessions -> sid (varchar(128)) ?
Sessions -> ssid (varchar(128)) ?
Sessions -> hostname (varchar(128)) -> OK
Sessions -> timestamp (int(11)) -> guessing date of connection
Sessions -> cache (int(11)) -> Why only an integer ?
Sessions -> session (longblob) -> What do you put inside ?
As I imagined my own diagram, I had 2 tables :
Session that stored the sessionId, cookie and establishing date
User_Session, association between Sessions and Users, which stores IP address and DateInit.
Why not storing one session by Cookie and storing also each time the user connects ?
If someone could help me understand and help me find the true entity-relationship model...

Description of the session table from Drupal 7 is given in its system_schema() function:
$schema['sessions'] = array(
'description' => "Drupal's session handlers read and write into the sessions table. Each record represents a user session, either anonymous or authenticated.",
'fields' => array(
'uid' => array(
'description' => 'The {users}.uid corresponding to a session, or 0 for anonymous user.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'sid' => array(
'description' => "A session ID. The value is generated by Drupal's session handlers.",
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
),
'ssid' => array(
'description' => "Secure session ID. The value is generated by Drupal's session handlers.",
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
),
'hostname' => array(
'description' => 'The IP address that last used this session ID (sid).',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
),
'timestamp' => array(
'description' => 'The Unix timestamp when this session last requested a page. Old records are purged by PHP automatically.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'cache' => array(
'description' => "The time of this user's last post. This is used when the site has specified a minimum_cache_lifetime. See cache_get().",
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'session' => array(
'description' => 'The serialized contents of $_SESSION, an array of name/value pairs that persists across page requests by this session ID. Drupal loads $_SESSION from here at the start of each request and saves it at the end.',
'type' => 'blob',
'not null' => FALSE,
'size' => 'big',
),
),
'primary key' => array(
'sid',
'ssid',
),
'indexes' => array(
'timestamp' => array('timestamp'),
'uid' => array('uid'),
'ssid' => array('ssid'),
),
'foreign keys' => array(
'session_user' => array(
'table' => 'users',
'columns' => array('uid' => 'uid'),
),
),
);
But this is not an E-R model. Also, it heavily depends on Drupal own session handling function.

Related

CCK field with multiple fields inside

im new on drupal and im having a problem with CCK fields.
I made a custom cck field and the install schema its like this:
function usig_location_field_schema($field) {
return array(
'columns' => array(
'location_cck_usig' => array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
),
'lat_cck_usig' => array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
),
'lon_cck_usig' => array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
),
),
);
}
But when i save the new content .. drupal crash with this log :
Fatal error: Cannot create references to/from string offsets nor
overloaded objects in /includes/common.inc on line 6392
So .. i know that im doing something wrong. I just dont know which hook use to save the fields.. (its possible save various fields at once ?)
Thx for all and sry for my english
You can always use this great module called Field Collection
Cheers

Drupal 6 schema not installing all tables

So this has been driving me crazy for 2 days, I have a module I've written that uses 3 DB tables, 2 of them install perfectly, and this is the third one:
$schema['tags_twistal'] = array(
'description' => t('Taxonomy for videos (tags)'),
'fields' => array(
'vid' => array(
'description' => t('The video ID'),
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'tag' => array(
'description' => t('The tag name'),
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
),
'primary key' => array('tag','vid'),
);
All I can think is that it has something to do with the primary key that I set, I've also tried:
'unique keys' => array(
'tag_vid' => array('tag', 'vid'),
),
'primary key' => array('tag_vid'),
Any ideas? I'm about to pull my hair out!
I'm having a similar issue in Drupal 7.
The tables of mine that install correctly are those which have a matching entry in the array returned by hook_node_info().
It looks as though Drupal will not create any tables that are not referenced in hook_node_info(), even if they are explicitly enumerated in hook_scheme(). I can't find this documented anywhere, but it matches my experience, and is a pain in the butt.

Drupal table creation error [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
I am trying to create a table in Drupal database using hook_schema function but I am getting the PDO exception error which I could not resolve. It would be great if you could provide me an solution to my issue
PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064
You have an error in your SQL syntax; check the manual that corresponds
to your MySQL server version for the right syntax to use near 'DEFAULT '' COMMENT
'first name of the user', `lname` VARCHAR DEFAULT '' COMMENT' at line 3:
CREATE TABLE {mage_user} ( `uid` INT unsigned NOT NULL auto_increment COMMENT
'The foreign identifier for a mage user.', `fname` VARCHAR DEFAULT ''
COMMENT 'first name of the user', `lname` VARCHAR DEFAULT '' COMMENT
'last name of the user', `address1` VARCHAR(255) DEFAULT '' COMMENT
'adress line 1', `address2` VARCHAR(255) DEFAULT '' COMMENT 'adress line 2',
`postcode` VARCHAR(7) DEFAULT '' COMMENT 'postcode', `gender` VARCHAR(6)
DEFAULT '' COMMENT 'gender' ) ENGINE = InnoDB DEFAULT CHARACTER SET utf8
COMMENT 'The base table for mage user.'; Array ( ) in db_create_table()
(line 2688 of E:\Server\drupal\includes\database\database.inc).
I am using
Apache/2.2.22 (Win32) PHP/5.3.10
MySQL client version: mysqlnd 5.0.8-dev - 20102224 - $Revision: 321634 $
MySQL server version 5.5.21
and my schema definition is
function mageacc_schema() {
$schema['mageuser'] = array(
'description' => 'The base table for mage user.',
'fields' => array(
'uid' => array(
'description' => 'The foreign identifier for a mage user.',
'type' => 'serial',
'not null' => TRUE,
),
'fname' => array(
'description' => 'first name of the user',
'type' => 'varchar',
'lenght' => 255,
'default' => '',
),
'lname' => array(
'description' => 'last name of the user',
'type' => 'varchar',
'lenght' => 255,
'default' => '',
),
'address1' => array(
'description' => 'adress line 1',
'type' => 'varchar',
'length' => 255,
'default' => '',
),
'address2' => array(
'description' => 'adress line 2',
'type' => 'varchar',
'length' => 255,
'default' => '',
),
'postcode' => array(
'description' => 'postcode',
'type' => 'varchar',
'length' => 7,
'default' => '',
),
'gender'=>array(
'description' => 'gender',
'type' => 'varchar',
'length' => 6,
'default' => '',
),
),
);
return $schema;
}
Thanks in Advance
I spotted a few typos with the 'length' property. Try fixing those first in fname and lname to see if it works.

set default value for custom field type: list_boolean / options_onoff

$instance = array(
'field_name' => $field_name,
'entity_type' => $entity,
'bundle' => $bundle,
'field types' => 'list_boolean',
'widget' => array(
'type' => 'options_onoff',
'settings' => array('display_label' => 1)
),
'default_value' => array(array('value' => 1)),
);
this is not taken, and i have to save it twice in the admin contenttype - field/edit,
until it takes it ...
i now exported the finished field with the features module,
and took the generated code - suddenly it works, with default_value
i guess i was missing the property module on the field, also field types is inexistant ..
In your field definition, you have to set the allowed_values in the settings array in order for the default_value in the instance to get picked up.
so like this assuming you are doing this in a module
$fields[] = array(
'field_name' => '$field_name',
'type' => 'list_boolean',
'settings' => array(
'allowed_values' => drupal_map_assoc(range(0, 1)),
),
);
Instead of using 'default_value', I got it to work by using 'default_value_function' and creating a function that returns array(array('value' => 1)).

Drupal 7: Make custom content translatable

I'm creating a custom module which enables me to add Countries to a custom table in the database. I'll do later more with it, but as I got stuck at the beginning, I can't go on.
First my piece of code:
function partners_schema()
{
$schema['partners_country'] = array(
'description' => 'TODO: please describe this table!',
'fields' => array(
'id' => array(
'description' => 'auto inc id of country',
'type' => 'serial',
'not null' => true,
),
'name' => array(
'description' => 'name of country',
'type' => 'varchar',
'length' => '255',
'not null' => true,
'translatable' => true,
),
'needDistributor' => array(
'description' => 'is a distributor needed',
'type' => 'int',
'size' => 'tiny',
'not null' => true,
),
),
'primary key' => array('id'),
);
return $schema;
}
The code above generates my Database table. After searching I found that I can add 'translatable' => true to my schema, so Drupal knows that this field is translatable content.
I've added a form, to insert data into that schema, but now I got stuck. What do I have to do, that the user is able to translate the column name?
Thanks for your help.
Have a look at the accepted answer on this post it should help clear a few things up.

Resources