Skip to content

Commit f24e0de

Browse files
authored
Merge pull request #557 from topcoder-platform/develop
v1.5
2 parents 41543dd + 753a1b1 commit f24e0de

33 files changed

+2443
-79
lines changed

.circleci/config.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ builddeploy_steps: &builddeploy_steps
2929
- run: *install_dependency
3030
- run: *install_deploysuite
3131
#- restore_cache: *restore_cache_settings_for_build
32-
- run: ./build.sh ${APPNAME} ${CI_DEPLOY_TOKEN} ${LOGICAL_ENV} ${BRANCH}
32+
- run: ./build.sh ${APPNAME} ${CI_DEPLOY_TOKEN} ${LOGICAL_ENV} ${BRANCH} ${TIDEWAYS_ENV}
3333
#- save_cache: *save_cache_settings
3434
- deploy:
3535
name: Running MasterScript.
@@ -52,6 +52,7 @@ jobs:
5252
APPNAME: "vanilla-forums"
5353
CI_DEPLOY_TOKEN: $CI_DEPLOY_TOKEN
5454
BRANCH: "develop"
55+
TIDEWAYS_ENV: "dev"
5556
steps: *builddeploy_steps
5657

5758
"build-prod":
@@ -62,6 +63,7 @@ jobs:
6263
APPNAME: "vanilla-forums"
6364
CI_DEPLOY_TOKEN: $CI_DEPLOY_TOKEN
6465
BRANCH: "master"
66+
TIDEWAYS_ENV: "production"
6567
steps: *builddeploy_steps
6668

6769
workflows:

Dockerfile

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@ ARG CI_DEPLOY_TOKEN
44
ARG VANILLA_VERSION=3.3
55
ARG ENV
66
ARG BRANCH
7+
ARG TIDEWAYS_ENV
78

8-
ENV TIDEWAYS_SERVICE vanilla
9+
ENV TIDEWAYS_SERVICE web
10+
ENV TIDEWAYS_ENVIRONMENT=$TIDEWAYS_ENV
11+
ENV TIDEWAYS_DAEMON_EXTRA="--env=$TIDEWAYS_ENVIRONMENT --debug"
912
ENV WEB_DOCUMENT_ROOT /vanillapp
1013

14+
RUN echo "Tideways Daemon for '$TIDEWAYS_ENV' env"
15+
1116
# Get the latest release of Vanilla Forums
1217
RUN wget https://github.com/vanilla/vanilla/releases/download/Vanilla_${VANILLA_VERSION}/vanilla-${VANILLA_VERSION}.zip
1318
RUN unzip vanilla-${VANILLA_VERSION}.zip -d /tmp
@@ -69,22 +74,23 @@ COPY ./vanilla/. /vanillapp/.
6974
RUN chown application:application /vanillapp/conf/config.php
7075
RUN chmod ug=rwx,o=rx /vanillapp/conf/config.php
7176

72-
7377
# Tideways
74-
RUN if [ "$ENV" = "dev" ]; then \
75-
apt-get update && apt-get install -y gnupg2; \
76-
echo 'deb https://packages.tideways.com/apt-packages debian main' > /etc/apt/sources.list.d/tideways.list && \
78+
RUN apt-get update && apt-get install -yq --no-install-recommends gnupg2;
79+
RUN echo 'deb https://packages.tideways.com/apt-packages debian main' > /etc/apt/sources.list.d/tideways.list && \
7780
curl -L -sS 'https://packages.tideways.com/key.gpg' | apt-key add - && \
7881
apt-get update && \
79-
DEBIAN_FRONTEND=noninteractive apt-get -yq install tideways-php && \
82+
DEBIAN_FRONTEND=noninteractive apt-get -yq install tideways-php tideways-daemon && \
8083
apt-get autoremove --assume-yes && \
8184
apt-get clean && \
8285
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*; \
83-
echo 'extension=tideways.so\ntideways.connection=tcp://tideways-daemon:9135\ntideways.enable_cli=0\n' >> opt/docker/etc/php/php.ini; \
84-
fi
86+
echo 'extension=tideways.so\ntideways.enable_cli=0\ntideways.sample_rate=25' >> opt/docker/etc/php/php.ini;
8587

8688
# Copy custom supervisor's configs and scripts
8789
# Netcat is used to connect to a memcached server
8890
RUN apt-get update && apt-get install -y netcat
89-
COPY ./services/flush_cache.conf /opt/docker/etc/supervisor.d/
90-
COPY ./services/flush_cache.sh /opt/docker/bin/service.d/
91+
COPY ./services/*.conf /opt/docker/etc/supervisor.d/
92+
COPY ./services/*.sh /opt/docker/bin/service.d/
93+
94+
# Ensure the service files are already executable
95+
RUN chmod +x /opt/docker/bin/service.d/flush_cache.sh
96+
RUN chmod +x /opt/docker/bin/service.d/tideways.sh

build.sh

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@ APP_NAME=$1
44
CI_DEPLOY_TOKEN=$2
55
ENV=$3
66
BRANCH=$4
7+
TIDEWAYS_ENV=$5
78
UPDATE_CACHE=""
89
echo "" > vanilla.env
9-
if [ "$ENV" = "dev" ]; then
10-
ENV=$ENV CI_DEPLOY_TOKEN=$CI_DEPLOY_TOKEN BRANCH=$BRANCH docker-compose -f docker-compose.yml -f docker-compose.dev.yml build $APP_NAME
11-
else
12-
ENV=$ENV CI_DEPLOY_TOKEN=$CI_DEPLOY_TOKEN BRANCH=$BRANCH docker-compose -f docker-compose.yml build $APP_NAME
13-
fi
10+
ENV=$ENV CI_DEPLOY_TOKEN=$CI_DEPLOY_TOKEN BRANCH=$BRANCH TIDEWAYS_ENV=$TIDEWAYS_ENV docker-compose -f docker-compose.yml build $APP_NAME
1411
#docker create --name app $APP_NAME:latest

config/vanilla/bootstrap.before.php

Lines changed: 77 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,46 @@ function dateUpdated($row, $wrap = null) {
327327
}
328328
}
329329

330+
if (!function_exists('watchIcon')) {
331+
/**
332+
*
333+
* Writes the Watch/watching icon
334+
*
335+
* @param int $categoryID
336+
* @return string
337+
*/
338+
function watchIcon($hasWatched = false, $title='') {
339+
if($hasWatched) {
340+
$icon = <<<EOT
341+
<svg width="21px" height="14px" viewBox="0 0 21 14" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
342+
<title>$title</title>
343+
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
344+
<g id="02-Challenge-Forums" transform="translate(-1261.000000, -328.000000)" fill="#0AB88A" fill-rule="nonzero">
345+
<path d="M1271.08333,328 C1266.5,328 1262.58583,330.850833 1261,334.875 C1262.58583,338.899167 1266.5,341.75 1271.08333,341.75 C1275.66667,341.75 1279.58083,338.899167 1281.16667,334.875 C1279.58083,330.850833 1275.66667,328 1271.08333,328 Z M1271.08333,339.458333 C1268.55333,339.458333 1266.5,337.405 1266.5,334.875 C1266.5,332.345 1268.55333,330.291667 1271.08333,330.291667 C1273.61333,330.291667 1275.66667,332.345 1275.66667,334.875 C1275.66667,337.405 1273.61333,339.458333 1271.08333,339.458333 Z M1271.08333,332.125 C1269.56167,332.125 1268.33333,333.353333 1268.33333,334.875 C1268.33333,336.396667 1269.56167,337.625 1271.08333,337.625 C1272.605,337.625 1273.83333,336.396667 1273.83333,334.875 C1273.83333,333.353333 1272.605,332.125 1271.08333,332.125 Z" id="Shape"></path>
346+
</g>
347+
</g>
348+
</svg>
349+
EOT;
350+
} else {
351+
$icon = <<<EOT
352+
<svg width="22px" height="22px" viewBox="0 0 22 22" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
353+
<title>$title</title>
354+
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
355+
<g id="02-Challenge-Forums" transform="translate(-1260.000000, -594.000000)">
356+
<g id="watch-icon" transform="translate(1260.000000, 594.000000)">
357+
<polygon id="Path" points="0 0 22 0 22 22 0 22"></polygon>
358+
<path d="M11,6.41666667 C14.4741667,6.41666667 17.5725,8.36916667 19.085,11.4583333 C17.5725,14.5475 14.4741667,16.5 11,16.5 C7.52583333,16.5 4.4275,14.5475 2.915,11.4583333 C4.4275,8.36916667 7.52583333,6.41666667 11,6.41666667 M11,4.58333333 C6.41666667,4.58333333 2.5025,7.43416667 0.916666667,11.4583333 C2.5025,15.4825 6.41666667,18.3333333 11,18.3333333 C15.5833333,18.3333333 19.4975,15.4825 21.0833333,11.4583333 C19.4975,7.43416667 15.5833333,4.58333333 11,4.58333333 Z M11,9.16666667 C12.265,9.16666667 13.2916667,10.1933333 13.2916667,11.4583333 C13.2916667,12.7233333 12.265,13.75 11,13.75 C9.735,13.75 8.70833333,12.7233333 8.70833333,11.4583333 C8.70833333,10.1933333 9.735,9.16666667 11,9.16666667 M11,7.33333333 C8.72666667,7.33333333 6.875,9.185 6.875,11.4583333 C6.875,13.7316667 8.72666667,15.5833333 11,15.5833333 C13.2733333,15.5833333 15.125,13.7316667 15.125,11.4583333 C15.125,9.185 13.2733333,7.33333333 11,7.33333333 Z" id="Shape" fill="#555555" fill-rule="nonzero"></path>
359+
</g>
360+
</g>
361+
</g>
362+
</svg>
363+
EOT;
364+
}
365+
366+
return $icon;
367+
}
368+
}
369+
330370
if (!function_exists('watchButton')) {
331371
/**
332372
*
@@ -335,27 +375,25 @@ function dateUpdated($row, $wrap = null) {
335375
* @param int $categoryID
336376
* @return string
337377
*/
338-
function watchButton($categoryID) {
378+
function watchButton($category) {
339379
$output = ' ';
340380
$userID = Gdn::session()->UserID;
341-
$category = CategoryModel::categories($categoryID);
381+
if(is_numeric($category)) {
382+
$category = CategoryModel::categories($category);
383+
}
342384

343-
if ($userID && $category && $category['DisplayAs'] == 'Discussions') {
385+
//if ($userID && $category && $category['DisplayAs'] == 'Discussions') {
386+
if ($userID && $category) {
344387
$categoryModel = new CategoryModel();
388+
$categoryID= val('CategoryID', $category);
345389
$hasWatched = $categoryModel->hasWatched($categoryID, $userID);
346-
$iconTitle = t('Watch');
347-
$icon = <<<EOT
348-
<svg xmlns="http://www.w3.org/2000/svg" class="watchButton-icon" viewBox="0 0 16 16" aria-hidden="true">
349-
<title>{$iconTitle}</title>
350-
<path d="M7.568,14.317a.842.842,0,0,1-1.684,0,4.21,4.21,0,0,0-4.21-4.21h0a.843.843,0,0,1,0-1.685A5.9,5.9,0,0,1,7.568,14.317Zm4.21,0a.842.842,0,0,1-1.684,0A8.421,8.421,0,0,0,1.673,5.9h0a.842.842,0,0,1,0-1.684,10.1,10.1,0,0,1,10.105,10.1Zm4.211,0a.842.842,0,0,1-1.684,0A12.633,12.633,0,0,0,1.673,1.683.842.842,0,0,1,1.673,0,14.315,14.315,0,0,1,15.989,14.315ZM1.673,16a1.684,1.684,0,1,1,1.684-1.684h0A1.684,1.684,0,0,1,1.673,16Z" transform="translate(0.011 0.001)" style="fill: currentColor;"/>
351-
</svg>
352-
EOT;
353390

354-
$text = $hasWatched ? t('Watching') : t('Watch');
391+
$text = $hasWatched ? t('Stop watching the category') : t('Watch the category');
392+
$icon = watchIcon($hasWatched, $text);
355393
$output .= anchor(
356-
$icon . $text,
394+
$icon,
357395
$hasWatched ? "/category/watched/{$categoryID}/" . Gdn::session()->transientKey() : "/category/watch/{$categoryID}/" . Gdn::session()->transientKey(),
358-
'Hijack watchButton' . ($hasWatched ? ' TextColor isWatching' : ''),
396+
'Hijack watchButton' . ($hasWatched ? ' isWatching' : ''),
359397
['title' => $text, 'aria-pressed' => $hasWatched ? 'true' : 'false', 'role' => 'button', 'tabindex' => '0']
360398
);
361399
}
@@ -806,6 +844,32 @@ function myDraftsMenuItem($CountDrafts) {
806844
}
807845
}
808846

847+
if (!function_exists('myWatchingMenuItem')) {
848+
/**
849+
*
850+
*
851+
* @param $CountBookmarks
852+
* @return string
853+
*/
854+
function myWatchingMenuItem($CountWatches) {
855+
if (!Gdn::session()->isValid()) {
856+
return '';
857+
}
858+
$watching = t('Watching');
859+
$watching .= FilterCountString($CountWatches, '/watching');
860+
$cssClass = 'MyWatching';
861+
Logger::event(
862+
'topcoder_plugin',
863+
Logger::DEBUG,
864+
'myWatchingMenuItem:'.Gdn::controller()->RequestMethod,
865+
[]
866+
);
867+
$cssClass .= Gdn::controller()->ControllerName == 'watchingcontroller' ? ' Active' : '';
868+
$cssClass .= $CountWatches == 0 ? ' hidden': '';
869+
return sprintf('<li id="MyWatching" class="%s">%s</li>', $cssClass, anchor(sprite('SpBookmarks').$watching, '/watching'));
870+
}
871+
}
872+
809873
if(!function_exists('writeInlineDiscussionOptions')) {
810874
function writeInlineDiscussionOptions($discussionRow) {
811875
$discussionID = val('DiscussionID', $discussionRow);

config/vanilla/bootstrap.early.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,4 +152,21 @@
152152
->column('DateExpires', 'datetime')
153153
->set(false, false);
154154
}
155+
156+
// FIX: https://github.com/topcoder-platform/forums/issues/479
157+
if(!Gdn::structure()->table('User')->columnExists('CountWatchedCategories')) {
158+
Gdn::structure()->table('User')
159+
->column('CountWatchedCategories', 'int', true)
160+
->set(false, false);
161+
162+
// Set count of Watched Categories for users
163+
Gdn::sql()->query('update GDN_User u, (select wc.UserID, count(wc.CategoryID) count from GDN_Category c
164+
join (select distinct um.UserID, SUBSTRING_INDEX(um.Name, ".", -1) as CategoryID from GDN_UserMeta um where um.Name LIKE "Preferences.%" and Value = 1) wc
165+
where wc.CategoryID = c.CategoryID group by wc.UserID) uc
166+
set u.CountWatchedCategories = uc.count
167+
where u.UserID = uc.UserID', 'update');
168+
169+
Gdn::sql()->query('update GDN_User u set u.CountWatchedCategories = 0 where u.CountWatchedCategories is null', 'update');
170+
}
171+
155172
}

docker-compose.dev.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@ services:
77
container_name: tideways-daemon
88
build:
99
context: ./tideways-daemon
10+
args:
11+
- TIDEWAYS_ENV
1012
ports:
1113
- 9135:9135

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ services:
1212
- VANILLA_VERSION=3.3
1313
- CI_DEPLOY_TOKEN
1414
- BRANCH
15+
- TIDEWAYS_ENV
1516
ports:
1617
- 80:80

services/tideways.conf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[group:tideways]
2+
programs=tideways
3+
priority=10
4+
5+
[program:tideways]
6+
command=/opt/docker/bin/service.d/tideways.sh
7+
process_name=%(program_name)s
8+
startsecs=0
9+
startretries=0
10+
autostart=true
11+
autorestart=false
12+
stdout_logfile=/dev/stdout
13+
stdout_logfile_maxbytes=0
14+
stderr_logfile=/dev/stderr
15+
stderr_logfile_maxbytes=0

services/tideways.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh
2+
echo tideways.sh: Tideways Daemon for $TIDEWAYS_ENVIRONMENT
3+
/etc/init.d/tideways-daemon start
4+
exit_code=$?
5+
if [ $exit_code != 0 ]; then
6+
echo tideways.sh: exit code $exit_code
7+
else
8+
echo tideways.sh: started successfully.
9+
fi

tideways-daemon/Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
FROM debian:stable-slim
22

3-
ARG TIDEWAYS_ENVIRONMENT_DEFAULT=production
4-
ENV TIDEWAYS_ENVIRONMENT=$TIDEWAYS_ENVIRONMENT_DEFAULT
3+
ARG TIDEWAYS_ENV
4+
ENV TIDEWAYS_ENVIRONMENT=$TIDEWAYS_ENV
5+
RUN echo "Tideways Daemon container for '$TIDEWAYS_ENV' env"
56

67
RUN useradd --system tideways
78
RUN apt-get update && apt-get install -yq --no-install-recommends gnupg2 curl sudo ca-certificates

0 commit comments

Comments
 (0)