Skip to content

Commit

Permalink
migrate & init()
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Hendrickson committed Oct 22, 2009
1 parent e886aac commit 96e659a
Show file tree
Hide file tree
Showing 5 changed files with 235 additions and 28 deletions.
12 changes: 0 additions & 12 deletions app/omb/models/Aggregate.php
Expand Up @@ -26,18 +26,6 @@ function Aggregate() {

function init() {

$Cat = $this->base();
$Cat->set_value( 'name', 'Posts' );
$Cat->set_value( 'term', 'posts' );
$Cat->set_value( 'scheme', 'minifeed' );
$Cat->save_changes();

$Cat = $this->base();
$Cat->set_value( 'name', 'Tweets' );
$Cat->set_value( 'term', 'tweets' );
$Cat->set_value( 'scheme', 'minifeed' );
$Cat->save_changes();

}

}
Expand Down
15 changes: 12 additions & 3 deletions app/omb/models/Group.php
Expand Up @@ -30,17 +30,26 @@ function Group() {

function init() {

$this->set_limit(100);
$this->find();
$found = array();
while ($rec = $this->MoveNext())
$found[] = $rec->name;

$Grp = $this->base();
$Grp->set_value( 'name', 'everyone' );
$Grp->save_changes();
if (!(in_array($Grp->attributes['name'],$found)))
$Grp->save_changes();

$Grp = $this->base();
$Grp->set_value( 'name', 'administrators' );
$Grp->save_changes();
if (!(in_array($Grp->attributes['name'],$found)))
$Grp->save_changes();

$Grp = $this->base();
$Grp->set_value( 'name', 'members' );
$Grp->save_changes();
if (!(in_array($Grp->attributes['name'],$found)))
$Grp->save_changes();

}

Expand Down
11 changes: 9 additions & 2 deletions app/omb/models/Membership.php
Expand Up @@ -32,11 +32,18 @@ function Membership() {
}

function init() {


$this->set_limit(100);
$this->find();
$found = array();
while ($rec = $this->MoveNext())
$found[] = $rec->group_id;

$M = $this->base();
$M->set_value( 'group_id', 2 );
$M->set_value( 'person_id', 1 );
$M->save_changes();
if (!(in_array($M->attributes['group_id'],$found)))
$M->save_changes();

}

Expand Down
220 changes: 210 additions & 10 deletions app/omb/models/Method.php
Expand Up @@ -30,6 +30,13 @@ function Method() {

function init() {

$this->set_limit(100);
$this->find();
$methods = array();
while ($m = $this->MoveNext())
$methods[] = $m->function;


$m = $this->base();
$m->set_value( 'code', '
Expand Down Expand Up @@ -93,9 +100,10 @@ function init() {
$m->set_value( 'oauth', 1 );
$m->set_value( 'http', 1 );

$m->save_changes();
$m->set_etag(1);

if (!(in_array($m->attributes['function'],$methods))){
$m->save_changes();
$m->set_etag(1);
}

$m = $this->base();
$m->set_value( 'code', '
Expand All @@ -119,8 +127,10 @@ function init() {
$m->set_value( 'oauth', 1 );
$m->set_value( 'http', 1 );

$m->save_changes();
$m->set_etag(1);
if (!(in_array($m->attributes['function'],$methods))){
$m->save_changes();
$m->set_etag(1);
}

$m = $this->base();
$m->set_value( 'code', '
Expand Down Expand Up @@ -169,8 +179,10 @@ function init() {
$m->set_value( 'oauth', 1 );
$m->set_value( 'http', 1 );

$m->save_changes();
$m->set_etag(1);
if (!(in_array($m->attributes['function'],$methods))){
$m->save_changes();
$m->set_etag(1);
}


$m = $this->base();
Expand Down Expand Up @@ -231,11 +243,199 @@ function init() {
$m->set_value( 'oauth', 1 );
$m->set_value( 'http', 1 );

$m->save_changes();
$m->set_etag(1);
if (!(in_array($m->attributes['function'],$methods))){
$m->save_changes();
$m->set_etag(1);
}



$m = $this->base();
$m->set_value( 'code', '
global $blogdata;
$blogdata[\'rss2_url\'] =$_POST[\'url1\'];
add_include_path(library_path());
include_once(\'rsscloud/rsscloud.php\');
rsscloud_hub_process_notification_request();
');

$m->set_value( 'function', 'api_rsscloud_pleaseNotify' );
$m->set_value( 'route', 'api/rsscloud/pleaseNotify' );
$m->set_value( 'resource', 'posts' );
$m->set_value( 'permission', 'read' );
$m->set_value( 'enabled', true );
$m->set_value( 'omb', 1 );
$m->set_value( 'oauth', 1 );
$m->set_value( 'http', 1 );

if (!(in_array($m->attributes['function'],$methods))){
$m->save_changes();
$m->set_etag(1);
}

$m = $this->base();
$m->set_value( 'code', '
global $db,$request,$response;
extract($vars);
$Feed =& $db->model(\'Feed\');
$f = $Feed->find_by(\'xref\',$_POST[\'url\']);
if ($f->profile_id) {
$profile_id = $f->profile_id;
$url = $_POST[\'url\'];
} else {
exit;
}
$items = array();
$title = \'\';
$link = \'\';
$description = \'\';
$buf = readURL($url);
$xml = new SimpleXmlElement($buf);
foreach($xml as $k1=>$v1){
foreach($v1 as $k2=>$v2){
$link = \'\';
if ($k2 == \'item\') {
foreach($v2 as $k3=>$v3){
if ($k3 == \'title\')
$title = (string)$v3;
if ($k3 == \'link\')
$link = (string)$v3;
if ($k3 == \'description\')
$description = (string)$v3;
}
if (!empty($link))
$items[] =array(
\'title\'=>$title,
\'link\'=>$link,
\'description\'=>$description
);
}
}
}
$profile = get_profile($profile_id);
$response->set_var(\'profile\',$profile);
load_apps();
$Post =& $db->model(\'Post\');
foreach($items as $feeditem){
$p = $Post->find_by(\'url\',$feeditem[\'link\']);
if ($p)
continue;
$table = \'posts\';
$Post =& $db->model(\'Post\');
$modelvar = \'Post\';
$request->set_param(\'resource\',$table);
trigger_before( \'insert_from_post\', $$modelvar, $request );
$content_type = \'text/html\';
$rec = $$modelvar->base();
$rec->set_value(\'profile_id\',$profile_id);
$rec->set_value( \'parent_id\', 0 );
$rec->set_value( \'title\', $feeditem[\'title\'] );
$rec->set_value( \'body\', $feeditem[\'description\'] );
$rec->set_value( \'uri\', $feeditem[\'link\'] );
$rec->set_value( \'url\', $feeditem[\'link\'] );
$rec->save_changes();
$atomentry = $$modelvar->set_metadata($rec,$content_type,$table,\'id\');
trigger_after( \'insert_from_post\', $$modelvar, $rec );
}
header( \'Status: 200 OK\' );
exit;
');

$m->set_value( 'function', 'api_rsscloud_callback' );
$m->set_value( 'route', 'api/rsscloud/callback' );
$m->set_value( 'resource', 'posts' );
$m->set_value( 'permission', 'read' );
$m->set_value( 'enabled', true );
$m->set_value( 'omb', 1 );
$m->set_value( 'oauth', 1 );
$m->set_value( 'http', 1 );

if (!(in_array($m->attributes['function'],$methods))){
$m->save_changes();
$m->set_etag(1);
}

$m = $this->base();
$m->set_value( 'code', '
global $blogdata;
$blogdata[\'rss2_url\'] = $_POST[\'url\'];
add_include_path(library_path());
include_once(\'rsscloud/rsscloud.php\');
$notify_rss = get_bloginfo( \'rss2_url\' );
$listeners = rsscloud_get_hub_notifications();
if (!is_array($listeners))
return;
foreach ( $listeners[$notify_rss] as $notify_url => $n ) {
if ( $n[\'status\'] == \'active\' ) {
if ( $n[\'protocol\'] == \'http-post\' ) {
$url = parse_url( $notify_url );
$port = 80;
if ( !empty( $url[\'port\'] ) )
$port = $url[\'port\'];
$notify_vars="url=" . $notify_rss;
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $notify_url);
curl_setopt ($ch, CURLOPT_HEADER, 0); /// Header control
curl_setopt ($ch, CURLOPT_PORT, $port);
curl_setopt ($ch, CURLOPT_POST, true); /// tell it to make a POST, not a GET
curl_setopt ($ch, CURLOPT_POSTFIELDS, $notify_vars);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$xml_response = curl_exec ($ch);
curl_close ($ch);
$need_update = false;
if ( $result[\'response\'][\'code\'] != 200 ) {
$notify[$rss2_url][$notify_url][\'failure_count\']++;
$need_update = true;
} elseif ( $notify[$rss2_url][$notify_url][\'failure_count\'] > RSSCLOUD_MAX_FAILURES ) {
$notify[$rss2_url][$notify_url][\'status\'] = \'suspended\';
$need_update = true;
}
}
}
}
if ( $need_update )
rsscloud_update_hub_notifications( $notify );
');

$m->set_value( 'function', 'api_rsscloud_ping' );
$m->set_value( 'route', 'api/rsscloud/ping' );
$m->set_value( 'resource', 'posts' );
$m->set_value( 'permission', 'read' );
$m->set_value( 'enabled', true );
$m->set_value( 'omb', 1 );
$m->set_value( 'oauth', 1 );
$m->set_value( 'http', 1 );

if (!(in_array($m->attributes['function'],$methods))){
$m->save_changes();
$m->set_etag(1);
}

}


}

5 changes: 4 additions & 1 deletion db/library/dbscript/_functions.php
Expand Up @@ -2475,8 +2475,11 @@ function migrate() {
$db->just_get_objects();

foreach($db->models as $model)
if ($model)
if ($model){
$model->migrate();
if (method_exists( $model, 'init' ))
$model->init();
}

echo "<br />The database schema is now synced to the data models. <a href=\"".$request->url_for('admin')."\">Return to Admin</a><br /><br />";
exit;
Expand Down

0 comments on commit 96e659a

Please sign in to comment.