Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
noblogs-wp
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ai
noblogs-wp
Commits
8ae70483
Commit
8ae70483
authored
14 years ago
by
root
Committed by
agata
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add utility to discover the blog backend given its name
parent
109035ee
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
r2db/tools/get-backend.php
+53
-0
53 additions, 0 deletions
r2db/tools/get-backend.php
with
53 additions
and
0 deletions
r2db/tools/get-backend.php
0 → 100755
+
53
−
0
View file @
8ae70483
#!/opt/noblogs/cron/php-noblogs
<?php
if
(
$argv
[
1
])
{
$blog_domain
=
$argv
[
1
];
if
(
!
preg_match
(
'/\.noblogs\.org$/'
,
$blog_domain
))
{
$blog_domain
=
$blog_domain
.
'.noblogs.org'
;
}
}
else
{
die
(
"Usage: get-backend <blog_name>
\n
"
);
}
// Load wordpress api.
define
(
'WP_CACHE'
,
false
);
/** Setup WordPress environment */
require_once
(
'wp-load.php'
);
require_once
(
'db-config.php'
);
function
new_hash
(
$dbid
,
$reversemap
)
{
global
$wpdb
;
$lookup
=
$wpdb
->
hash_map
->
lookup
(
$dbid
);
$backend
=
$reversemap
[
$lookup
];
$result
=
array
();
if
(
preg_match
(
'/^(.*):([0-9]*)$/'
,
$backend
[
'host'
],
$matches
))
{
$result
[
'host'
]
=
$matches
[
1
];
$result
[
'port'
]
=
$matches
[
2
];
}
$result
[
'user'
]
=
$backend
[
'user'
];
$result
[
'password'
]
=
$backend
[
'password'
];
$result
[
'db'
]
=
$backend
[
'name'
];
return
$result
;
}
function
get_blog
(
$domain
)
{
global
$wpdb
;
// $sql = "SELECT blog_id, domain, path FROM $wpdb->blogs WHERE public = 1 AND deleted = 0 AND archived = '0' ORDER BY domain, path";
$sql
=
"SELECT blog_id, domain, path FROM
$wpdb->blogs
WHERE domain = '"
.
$domain
.
"'"
;
$result
=
$wpdb
->
get_results
(
$sql
);
return
(
$result
[
0
]);
}
$hashmap
=
new
Flexihash
();
$reverse_backend_map
=
noblogs_load_backends
(
NOBLOGS_BACKEND_CONFIG
,
$hashmap
);
$blog
=
get_blog
(
$blog_domain
);
$backend
=
new_hash
(
$blog
->
blog_id
,
$reverse_backend_map
);
echo
"
\n
"
.
$blog_domain
.
" (id "
.
$blog
->
blog_id
.
")
\n\n
"
;
print_r
(
$backend
);
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment